我有两个桌子

餐桌假

ID   | TYPE
1      Annual
2      Sick
3      Unpaid
4      Marriage


表离开数据

IDLEAVEDATA   | LEAVETYPE*
1                 1
2                 1
3                 2
4                 2


LEAVETYPE是外键(请参阅表假中的ID)

如何计算ID在表LeaveData中的出现?

输出示例:

TYPE         |  COUNT
Annual          2
Sick            2
Unpaid          0 or null
Marriage        0 or null

最佳答案

尝试,

SELECT  l.TYPE , COUNT(ld.LEAVETYPE) as COUNT
FROM    Leave AS l
LEFT JOIN LeaveData AS ld ON ld.LEAVETYPE = L.ID
GROUP BY  ld.LEAVETYPE

关于mysql - mysql连接数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3798456/

10-10 06:48