SQL -左连接上没有null

时间:2022-09-21 09:36:42

I have been working with a Chart control in a WinForms Application, and have had some trouble with plotting the correct points - i have tried a multitude of things including the DataManipulator.InsertEmptyPoints, to no avail.

我一直在WinForms应用程序中使用图表控件,并且在绘制正确的点上遇到了一些麻烦——我尝试了很多东西,包括DataManipulator。InsertEmptyPoints,无济于事。

So, i decided to improve my SQL Query - which has been done, but it is still not including 0/Null Values - but i'm having some trouble with my left join - it's not returning any Null Values.

因此,我决定改进我的SQL查询——已经完成了,但是它仍然不包括0/Null值——但是我的左连接有一些问题——它没有返回任何空值。

Query:

查询:

SELECT FC_Name , count (Findings.Findings_ID) AS 'NumFindings'
FROM FindingCategories
     LEFT JOIN Findingsubcategories ON Findingsubcategories.FC_ID = FindingCategories.FC_ID
     LEFT JOIN Findings ON Findings.FSC_ID = Findingsubcategories.FSC_ID
     -- LEFT JOIN Audit ON Audit.Audit_ID = Findings.AU_ID
     -- WHERE Audit.Audit_ID = 932
     GROUP BY FC_Name

The output of the query

查询的输出

SQL -左连接上没有null

Now, when i remove my comments and include the two lines in the query

现在,当我删除我的注释并包含查询中的两行。

SQL -左连接上没有null

Where as i want it to be something like:

我想要的是:

FC_Name    | NumFindings
Category         1
Category         6
Category         1
Category         0/Null
Category         0/Null
Category         0/Null
Category         0/Null

What am i doing wrong?

我做错了什么?

1 个解决方案

#1


3  

I managed to deduce that one of my joins was redundant and didnt do anything, the solution:

我设法推断出,我的一个连接是多余的,没有做任何事情,解决方法是:

SELECT FC_Name, COUNT(Findings.Findings_ID) AS 'NumFindings'
FROM FindingCategories
 LEFT OUTER JOIN Findingsubcategories ON Findingsubcategories.FC_ID = FindingCategories.FC_ID
 LEFT OUTER JOIN Findings ON Findings.FSC_ID = Findingsubcategories.FSC_ID AND Findings.AU_ID = 932
 GROUP BY FC_Name

#1


3  

I managed to deduce that one of my joins was redundant and didnt do anything, the solution:

我设法推断出,我的一个连接是多余的,没有做任何事情,解决方法是:

SELECT FC_Name, COUNT(Findings.Findings_ID) AS 'NumFindings'
FROM FindingCategories
 LEFT OUTER JOIN Findingsubcategories ON Findingsubcategories.FC_ID = FindingCategories.FC_ID
 LEFT OUTER JOIN Findings ON Findings.FSC_ID = Findingsubcategories.FSC_ID AND Findings.AU_ID = 932
 GROUP BY FC_Name