我有两个使用三个表的select语句。我需要能够从这些创建一个表,并说如果select语句1然后为用户分配值= 10,如果select语句2然后为user_id分配值= 7.在我的新表中我将拥有user_id并将其值如果case语句的计算结果为true,则分配。我一直在为我编写的任何案例陈述获取语法错误
SELECT m.user_id,f.manager_id
from sales b
JOIN promotions m on b.user_id = m.user_id
JOIN promotions f on b.user_sub_id = f.user_id
where m.address = f.address
and m.post = '95103'
SELECT m.user_id,f.manager_id
from sales b
JOIN promotions m on b.user_id = m.user_id
JOIN promotions f on b.user_sub_id = f.user_id
where m.address = f.address
and m.post = '98746'
AND f.address <> 'NULL' AND
NOT EXISTS (SELECT 1
FROM payments c
WHERE c.member_id = b.user_sub_id AND
c.status <> 'NULL'
AND c.info = 'T'
)
答案 0 :(得分:2)
到目前为止你做了什么?不需要案例陈述。
select *
into #Output
from (
-- select statement 1
select 10 as UserValue
, m.user_id
, f.manager_id
union all
-- select statement 2
select 7 as UserValue
, m.user_id
, f.manager_id
) a