MYSQL分组依据,用于单独的ID

时间:2019-03-27 15:22:29

标签: mysql join left-join

结构和查询如下:http://www.sqlfiddle.com/#!9/de7ec8/4

这是结果:

+-------------+--------+
| id_requests | status |
+-------------+--------+
|           1 |      0 |
|           1 |      0 |
|           1 |      1 |
|           2 |      1 |
+-------------+--------+
4 rows in set

我正在寻找结果:

+-------------+--------+
| id_requests | status |
+-------------+--------+
|           1 |      0 |
|           1 |      1 |
|           2 |      1 |
+-------------+--------+
3 rows in set

我想按状态分组,但是对于每个id_requests,我们将不胜感激。

1 个答案:

答案 0 :(得分:2)

您似乎正在为此使用distingle子句选择不同的行

SELECT distinct a.id_requests, b.status 
FROM `admin_availability_requests` a