考虑下表,例如
+----+-------+--------------+
| ID | TYPE | NAME |
+----+-------+--------------+
| 1 | 13 | Free color |
| 2 | 15 | Free food |
| 3 | 15 | Free burger |
| 4 | 17 | Free cloths |
| 5 | 13 | Free crayons |
| 6 | 12 | Free wood |
+----+-------+--------------+
我正在尝试构建一个查询,group by
只会在group by
列上使用普通type
来键入15,它会按所有类型进行分组,甚至13型,我不想要。我只想按特定值的列类型进行分组(此处为15)。在MySQL中有可能吗?如果是这样,怎么样?
预期结果如下所示:
+----+-------+--------------+
| ID | TYPE | NAME |
+----+-------+--------------+
| 1 | 13 | Free color |
| 2 | 15 | Free food |
| 4 | 17 | Free cloths |
| 5 | 13 | Free crayons |
| 6 | 12 | Free wood |
+----+-------+--------------+
答案 0 :(得分:2)
ActivityManager
答案 1 :(得分:-1)
为什么不进行两次查询?
SELECT * FROM table_name
WHERE Type = 15
GROUP BY Type
UNION ALL
SELECT * FROM table_name
WHERE Type <> 15