mysql - 如何消除mysql中的特定行
问题描述
id manager_id name
1 1 Tony
2 2 smith
3 2 harry
4 1 jack
5 1 william
6 2 steve
7 2 no name
8 2 john
9 2 no name
我使用此查询来获取相同的最后订购 id。
select t.*
from tablename t
where not exists (select 1
from tablename
where manager_id <> t.manager_id
and id > t.id)
| id | manager_id | name |
| --- | ---------- | ----- |
| 6 | 2 | steve |
| 7 | 2 | no name |
| 8 | 2 | john |
| 9 | 2 | no name |
上面的查询工作正常。但现在我需要消除 name = no name 的特定行。那么如何自定义查询。
解决方案
请使用以下查询来消除无名,
select t.*
from tablename t
where not exists (select 1
from tablename
where manager_id <> t.manager_id
and id > t.id) and t.name != 'no name';
推荐阅读
- javascript - 当我单击表格中的任何单元格时,如何强制唯一的单元格保留而不消失?
- apache-spark - Hive 元存储中的上次访问时间更新
- python - 替换数据框Python中列中的所有数值
- amazon-s3 - S3 下载 - SDK 与 lambda 函数内的 HTTP 请求
- json - 如何使用 Kotlin 操作 Mono 对象
- javascript - 将扩展运算符与 Promise.All() 一起使用会得到不同的结果,具体取决于哪个请求解决得更快?
- c++ - 将 4 个字节类型转换为 4 个字节的 int
- apache-spark - WAL 在 Spark Structured Streaming 中的位置
- macos - 在 Mac 上重置 USB 端口
- html - 使用 Thymleaf 映射绝对 URL 中的变量