假设我选择了这样的记录
+----+-------------------------------------------------------------------------------------
| id | groupedStatus |
+----+-------------------------------------------------------------------------------------
| 1 | received,accepted,discarded,discarded,accepted,discarded,accepted,received,received |
| 2 | accepted,discarded,received,received,received,received,received |
+----+-------------------------------------------------------------------------------------
除了上面的记录,我还想得到groupedstatus字符串中每个子字符串的出现情况,
例如,在第一行中,引用如下:
接收:3接受:3丢弃:3
原始表架构
表1
ID int
表2:
ID
Table1ID
Status enum('received','accepted','discarded')
我使用下面的查询选择上面的记录
select t1.id, group_concat(t2.status) as groupedStatus from Table1 t1 inner join Table2 t2 on t1.id=t2.table1ID group by t1.id
1条答案
按热度按时间tez616oj1#
您可以通过条件聚合来实现这一点,如下所示: