SELECT t1.id,Test1.name, t2.cnt_2,
t3.sum_pos, t3.sum_neg
FROM Test1 t1 LEFT JOIN
(SELECT ID_Test1, COUNT(*) as cnt_2
FROM Test2
GROUP BY ID_Test1
) t2
ON t1.id = t2.ID_Test1 LEFT JOIN
(SELECT ID_Test1, SUM(positive) as sum_pos, SUM(negative) as sum_neg
FROM Test3
GROUP BY ID_Test1
) t3
ON t1.id = t3.ID_Test1
GROUP BY t1.id;
1条答案
按热度按时间9ceoxa921#
你得到的是一个笛卡尔积
test1.id
. 您需要在JOIN
学生:这是sql小提琴。