我想选择一个名单列表作为输出。我想为所有wotranstype的添加 sitegm的名称 以及 execmgr的名称,仅当存在wotranstype budchg 且 prodmgr的名称时 仅适用于粗略的规划
到目前为止......我需要的结果集应该显示
因为没有交易类型的计划。
我尝试使用带有union的case语句并有条件地获取它们,如下所示。
(
SELECT
CASE WHEN t.wotranstype = 'budchg'
THEN w.SITEGM as recipient
else NULL
end
FROM wotrans T, wonotify w
WHERE T.PROJNUM = W.PROJNUM
)
UNION
(
SELECT
CASE WHEN t.wotranstype = 'planning'
THEN w.prodmgr as recipient
else NULL
end
FROM wotrans T, wonotify w
WHERE T.PROJNUM = W.PROJNUM
)
UNION
(...
答案 0 :(得分:0)
应该是:
select sitegm
from wotrans join wonotify using (projnum)
union all
select execmgr
from wotrans join wonotify using (projnum)
where wotranstype = 'budchg'
union all
select prodmgr
from wotrans join wonotify using (projnum)
where wotranstype = 'planning'
答案 1 :(得分:0)
我认为你正在使用UNION走上正轨。您是否尝试将标准放在WHERE部分而不是使用大小写,并使用UNION ALL:
(
SELECT
w.SITEGM as recipient
FROM wotrans T, wonotify w
WHERE T.PROJNUM = W.PROJNUM
AND t.wotranstype = 'budchg'
)
UNION ALL
(
SELECT
w.prodmgr as recipient
FROM wotrans T, wonotify w
WHERE T.PROJNUM = W.PROJNUM
AND t.wotranstype = 'planning'
)
UNION ALL
(...