34,587
社区成员
发帖
与我相关
我的任务
分享
select *,(select sum(0),sum(1) from table1 where pid=tabel2.pid) from tabel2
报错:Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
怎么可以 查出2个sum的结果放在表后面呢
连接
你直接用inner join关联相关字段进行sum啊
标量子查询只能一个字段,没办法。如果想要多个字段,就用连接的方式 join
select * from tabel2 a LEFT JOIN (select pid,sum(0) AS a,sum(1) AS b from table1 b GROUP BY pid ) b ON a.pid=b.pid