[英]Mysql Left Outer Join do not include all recs from left table
I have 2 tables: 我有2张桌子:
The left table1
just include ID and Status as text und just 5 Recs The table2
is linked by ID Table1 to an field which calls status in table2. 左
table1
只包含ID和状态文本UND仅有5份建议书的table2
由表1 ID链接到表2中调用地位的领域。
What I like to do is to sum the numbers of all types of status. 我想做的是汇总所有状态的数量。 My Idea was to using an left outer join an get a list of all status with numbers behind.
我的想法是使用左外部联接获取所有状态的列表,后面带有数字。 in Case there no linked recs from table2 to an status it should a
NULL
appears. 如果没有从table2链接到状态的记录,则应该显示
NULL
。
But my SQL statement just work like an ordinary join and bring only equal records. 但是我的SQL语句就像普通的联接一样工作,并且只带来相等的记录。 but not the records from table1 with NULL
但不是来自table1的NULL记录
I'd apreciate if you can have a look to my SQL statement: 如果您能看一下我的SQL语句,我将不胜感激:
SELECT task.tas_status
,v_task_status_1.param_str1
FROM v_task_status_1
LEFT OUTER JOIN task ON (v_task_status_1.param_id = task.tas_status)
You could use COUNT()
function to count and then use GROUP BY
as well 您可以使用
COUNT()
函数进行计数,然后也可以使用GROUP BY
SELECT
t2.tas_status,
COUNT(*) as CountPerStatus
FROM v_task_status_1 t1
LEFT OUTER JOIN task t2
ON t1.param_id = t2.tas_status
GROUP BY t2.tas_status
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.