gpt4 book ai didi

c# - sql中如何过滤空值

转载 作者:太空狗 更新时间:2023-10-30 00:39:54 25 4
gpt4 key购买 nike

我的sql语句有一个情况。在此 sql 语句中,我将 3 个表连接在一起(Application_Detail、Teacher_Detail 和 Class_Detail),然后我使用 WHERE 来过滤我的表以找出有多少老师使用了这个应用程序,我发现了以下结果。

在第一条记录中可以看到,teacher related 和 class related 字段都是空的。我想知道有没有办法过滤掉第 1 条记录,只显示第 2、3、4 条记录?因为我只想在 teacherId、teacherName、class 或 grade 列中有一些值时显示记录。

   teacherId teacherName   applicationName  class   grade
1. NULL NULL Excel NULL NULL
2. 5 NULL Excel NULL NULL
3. NULL NULL Excel A 6
4 NULL NULL Excel B 2

这是我的 SQL 命令

SELECT
td.teacherId,
teacherName,
applicationName,
class,
grade
FROM
[AppUser_Detail] as aud
LEFT OUTER JOIN [Teacher_Detail] as td ON aud.teacherId = td.teacherId
LEFT OUTER JOIN [Application_Detail] as ad ON aud.applicationId = ad.applicationId
LEFT OUTER JOIN [Class_Detail] as cd ON aud.classId = cd.classId
WHERE
aud.applicationId = 6 //I filter if my application Id is 6

最佳答案

试试这个:

SELECT
td.teacherId,
teacherName,
applicationName,
class,
grade
FROM
[AppUser_Detail] as aud
LEFT OUTER JOIN [Teacher_Detail] as td ON aud.teacherId = td.teacherId
LEFT OUTER JOIN [Application_Detail] as ad ON aud.applicationId = ad.applicationId
LEFT OUTER JOIN [Class_Detail] as cd ON aud.classId = cd.classId
WHERE
td.teacherId is not null OR class is not null OR grade is not null

关于c# - sql中如何过滤空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32627585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com