我有一个表格,结构如下:
登录OPEN_TIME CMD1 2018-09-17 17:13:06 61 2018-09-17 17:11:06 51 2018-09-17 17:15:06 42 2018-09 -…
使用查找所有登录的子查询 CMD != 6 ,然后过滤掉它们。
CMD != 6
SELECT * FROM yourTable WHERE login NOT IN ( SELECT login FROM yourTable WHERE cmd != 6)
要么
SELECT t1.* FROM yourTable AS t1 LEFT JOIN yourTable AS t2 ON t1.login = t2.login AND t2.cmd != 6 WHERE t2.login IS NULL
DEMO
您可以使用 NOT EXISTS
NOT EXISTS
SELECT * FROM Table WHERE NOT EXISTS ( SELECT 1 FROM Table WHERE cmd <> 6 )