SQL:left join和count聚合函数连接顺序

有三个表,现需要字段 type, count(likes),count(comments)三个表关联条件:a.id=b.id=c.id,但是有count怎么关联都不对显示错误,求指导!!

img

你就说行不行

SELECT 
CASE WHEN A.type=1 THEN '男' 
WHEN A.type=2 THEN '女'
ELSE '其它' END
,b.likes,c.comments
FROM 表a A
JOIN (SELECT id,COUNT(1) AS likes FROM 表b WHERE type=1 GROUP BY id) B
ON A.id=B.id
JOIN (SELECT id,COUNT(1) AS comments FROM 表c WHERE type=2 GROUP BY id) c
ON A.id=C.id

select type
case when a.type=1 then '男'
case when a.type=2 then '女'
else ‘其他’ end TYPES,
(select isnull(count(),0) from b where b.type= a.type) as likes,
(select isnull(count(
),0) from cwhere c.type= a.type) as comments
from 表a

把表结构以及你要实现什么功能描述出来比较好