gpt4 book ai didi

sql - 添加新列 SQL 查询

转载 作者:行者123 更新时间:2023-11-29 12:05:33 25 4
gpt4 key购买 nike

我有一个问题

select SUM(*) as "tot1" from table1 t, table2 t2 where t1.id=t2.id and t1.column=1

select SUM(*) as "tot2" from table1 t, table2 t2 where t1.id=t2.id and t1.column=2

select SUM(*) as "tot3" from table1 t, table2 t2 where t1.id=t2.id and t1.column=3

我想要这样的查询结果

 tot1     tot2     tot3

500 600 3

这可能吗?或者是否有任何替代解决方案让我在同一个表中查看这些查询。

最佳答案

试试这个:

select * from 
(select SUM(*) as "tot1" from table1 t, table2 t2 where t1.id=t2.id and t1.column=1) a,

(select SUM(*) as "tot2" from table1 t, table2 t2 where t1.id=t2.id and t1.column=2) b,

(select SUM(*) as "tot3" from table1 t, table2 t2 where t1.id=t2.id and t1.column=3) c

关于sql - 添加新列 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22428132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com