db2,with 子句,变量和多重连接

db2, with clause, variables and multiple join

我只是不知道如何使用创建和使用变量的好方法,如下例所示:

WITH t(myvar) AS (VALUES('welcome'))
SELECT tablename.*
FROM   tablename, t
WHERE  tablename.column1 = t.myvar

在这样的多连接查询中:

WITH t(myvar) AS (VALUES('welcomeagain'))
SELECT 
    tablename.*,
    joinedtable.valueid
FROM   
    tablename, t?
    left join joinedtable on
    joinedtable.keyid = tablename.keyid
WHERE  
    tablename.column1 = t.myvar

我的意思是,我必须在哪里、如何以及为了什么才能加入 "t"?环境是DB2 ISeries 7.2.

非常感谢您的帮助

马丁

也许这就是你想要的?

WITH t(myvar) AS (VALUES('welcomeagain'))
SELECT 
    tablename.*,
    t.myvar, 
    joinedtable.valueid
FROM   
    tablename
    join t on tablename.column1 = t.myvar
    left join joinedtable on joinedtable.keyid = tablename.keyid

或这个

WITH t(myvar) AS (VALUES('welcomeagain'))
SELECT 
    tablename.*,
    t.myvar, 
    joinedtable.valueid
FROM   
    tablename
    left join t on tablename.column1 = t.myvar
    left join joinedtable on joinedtable.keyid = tablename.keyid

或这个

WITH t(myvar) AS (VALUES('welcomeagain'))
SELECT 
    tablename.*,
    t.myvar, 
    joinedtable.valueid
FROM   
    tablename
    cross join t 
    left join joinedtable on joinedtable.keyid = tablename.keyid

您不想要的是逗号——因为这是旧式连接,将它与新式连接组合的语法总是有点迟钝(如果它有效的话)。