首页 MySql mysql – 如何从SQL中获取仅出现在特定值的条目?

mysql – 如何从SQL中获取仅出现在特定值的条目?

我需要在我的SQL表中找到始终只出现在某个值中的条目.例如:DeviceID Transmission ——– ———— 000329 Inventory 000980 Inventory 004406 Starting 000980 Stopping 000329 In

我需要在我的SQL表中找到始终只出现在某个值中的条目.

例如:

DeviceID    Transmission
--------    ------------
000329      Inventory
000980      Inventory
004406      Starting
000980      Stopping
000329      Inventory
004406      Inventory

现在我需要找到所有只有库存传输且从不启动或停止的DeviceID.在这种情况下000329.
最佳答案
您可以选择所有Transmission =’Inventory’id并过滤掉Transmission中的(‘Starting’,’Stopping’):

select distinct(DeviceID) from YourTable
WHERE Transmission = 'Inventory'
and DeviceID not in
( select distinct(DeviceID) from YourTable
  WHERE Transmission in('Starting','Stopping')
);

SQL小提琴:http://sqlfiddle.com/#!9/81896/12

本文来自网络,不代表青岛站长网立场。转载请注明出处: https://www.0532zz.com/html/shujuku/mysql/20210117/16466.html
上一篇
下一篇

作者: dawei

【声明】:青岛站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

返回顶部