今天遇到一项功能左面是分类、右侧是数据总和。
sql语句如下:
select B.*,
(select count(1) from Atable where id = 100 AND d = B.Id )
AS Number from Btable B whered = 22
SELECT B.* ,A.NUMS
FROM Btable B
LEFT OUTER JOIN
(select Id, count(*) AS NUMS from Atable where id = 22 GROUP BYId ) A
ON A.Id = B.Id
WHERE B.Id = 22