您好我使用此mysql代码生成以下数据:
代码:
SELECT L.LEAVETYPE, LA.IDLEAVETYPE, LA.IDLEAVETABLE, SUM( LA.NOOFDAYS )
FROM LEAVETYPE AS L
LEFT JOIN LEAVEAPPLICATION AS LA ON LA.IDLEAVETYPE = L.IDLEAVETYPETABLE
GROUP BY L.LEAVETYPE
当我添加Where条件时,它只会显示带有值的LeaveType。如何显示所有的leavetype,包括null(如第一张图片中所示)?
SELECT L.LEAVETYPE, LA.IDLEAVETYPE, LA.IDLEAVETABLE, SUM(LA.NOOFDAYS)
FROM LEAVETYPE AS L
LEFT JOIN LEAVEAPPLICATION AS LA ON LA.IDLEAVETYPE = L.IDLEAVETYPETABLE
WHERE LA.IDSTAFFTABLE='24'
GROUP BY L.LEAVETYPE
答案 0 :(得分:1)
将idstafftable条件移动到连接而不是where:
LEFT JOIN LEAVEAPPLICATION AS LA ON LA.IDLEAVETYPE = L.IDLEAVETYPETABLE AND LA.IDSTAFFTABLE='24'