当前位置 : 主页 > 网络编程 > 其它编程 >

SQL-左连接上没有null-SQL-NoNullsonLeftJoin

来源:互联网 收集:自由互联 发布时间:2023-07-02
IhavebeenworkingwithaChartcontrolinaWinFormsApplication,andhavehadsometroublewithp 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 t
IhavebeenworkingwithaChartcontrolinaWinFormsApplication,andhavehadsometroublewithp

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

查询的输出

Query with no Comment

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

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

enter image description here

Where as i want it to be something like:

我想要的是:

FC_Name | NumFindingsCategory 1Category 6Category 1Category 0/NullCategory 0/NullCategory 0/NullCategory 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
网友评论