2

我有下表:

alertID inspectorID datelive                dateread
1       none       2012-11-06 10:36:03.350  NULL
2       none       2012-11-06 10:36:25.043  NULL
3       none       2012-11-06 10:36:42.433  NULL
1       31030      2012-11-06 10:37:19.193  2012-06-11 10:34:47.000

我想选择没有针对它的检查员 ID 的警报,并且警报 ID 与具有针对它的检查员 ID 的警报 ID 不匹配,即检查员已读取警报 1,所以我只希望它返回警报 2 和 3

我正在使用经典 ASP 和 MS-SQL

4

3 回答 3

1

尝试这个

Select * From Alerts
Where AlertId Not In (Select AlertID From Alerts Where InspectorID IS NOT NULL)

这个想法是知道哪些 ID 对他们有 InspectorID,然后将它们从结果中排除NOT IN

于 2012-11-06T11:02:53.293 回答
0
SELECT *
FROM alertsTable
WHERE inspectorID IS NULL
AND alertID NOT IN (SELECT alertID FROM alertsTable where inspectorID IS NOT NULL)
于 2012-11-06T11:03:53.440 回答
0
Select * From Table
Where alertID Not In 
(Select alertID From Table Where inspectorID != 'none')
于 2012-11-06T11:05:47.617 回答