admin

如何在单独的列中合并多个选择语句?

sql

我有以下三个陈述:

select count (distinct vid) as SUM_OF_SEC from pdalis where pid in(500,504);
select sum (amount*paidperitem) SUM_OF_A from pdalis where pid = 501 ;
select sum(amount * paidperitem) SUM_OF_P from pdalis where pid IN (500,504);

如何将它们全部合并成3个并排的列?


阅读 277

收藏
2021-07-01

共1个答案

admin

尝试通过子查询

select count (distinct vid) as SUM_OF_SEC ,(select sum (amount*paidperitem) from pdalis where pid = 501 ;) AS SUM_OF_A , (select sum(amount * paidperitem) from pdalis where pid IN (500,504);) as SUM_OF_P  from pdalis where pid in(500,504);
2021-07-01