我在 MySQL 表中有以下数据。
+--------+----------+------+
| job_id | query_id | done |
+--------+----------+------+
| 15145 | a002 | 1 |
| 15146 | a002 | 1 |
| 15148 | a002 | 1 |
| 15150 | a002 | 1 |
| 15314 | a003 | 0 |
| 15315 | a003 | 1 |
| 15316 | a003 | 0 |
| 15317 | a003 | 0 |
| 15318 | a003 | 1 |
| 15319 | a003 | 0 |
+--------+----------+------+
我想知道是否有可能有一个 sql 查询,它可以按 query_id IF ALL 'done' 字段标记为 1。我想象的可能输出是:
+----------+------+
| query_id | done |
+----------+------+
| a002 | 1 |
| a003 | 0 |
+----------+------+
我尝试了以下 SQL 查询:
select job_id, query_id, done from job_table group by done having done = 1 ;
但没有运气。我真的很感激任何帮助!