0
我想寫一個SQL語句來獲取值的總和父內的所有兒童中包括一個輔助組的所有值:by子句
SELECT parent, child, sum(val)
FROM table_a
GROUP BY parent, child
ORDER BY parent, child
這是給我:
Parent1 Child1 123
Parent1 Child2 456
Parent2 Child1 789
Parent3 Child1 12
Parent3 Child2 345
我想要的是讓所有的孩子,而不僅僅是每個父母的父母下方的孩子,如果它沒有記錄分配它的值爲0。例如:
Parent1 Child1 123
Parent1 Child2 456
Parent2 Child1 789
Parent2 Child2 0
Parent3 Child1 12
Parent3 Child2 345
我可以用GROUP BY子句做到這一點嗎?或者我需要使用子查詢?