选择所有行值作为列表
我有一个表格的表:
userId caption status id
1 Paul done 1
2 Ali notDone 18
3 Kevin notDone 12
3 Elisa notDone 13
我将其加入另一个表用户
以查找task的数量
其中status = Notdone
。我这样做:
SELECT u.id,
t.number_of_tasks,
FROM users u
INNER JOIN (
SELECT userId, COUNT(*) number_of_tasks
FROM tasks
WHERE status = "notDone"
GROUP BY userId
) t ON u.id = t.userId
"""
现在,我想创建另一列字幕
以某种方式包含Count> Count> Count
和满足连接条件 +的条件。
例如,我希望这是行之一。我该如何实现?
userId number_of_tasks captions
3 2 ["Kevin", "Elisa"]
I have a table tasks
that looks like this:
userId caption status id
1 Paul done 1
2 Ali notDone 18
3 Kevin notDone 12
3 Elisa notDone 13
I join it with another table users
to find the number of tasks
where status = notDone
. I do it like this:
SELECT u.id,
t.number_of_tasks,
FROM users u
INNER JOIN (
SELECT userId, COUNT(*) number_of_tasks
FROM tasks
WHERE status = "notDone"
GROUP BY userId
) t ON u.id = t.userId
"""
Now, I want create another column captions
that somehow includes a list of all captions
that were included in the count
and fulfil the join + where conditions.
For example, I would expect this as one of the rows. How can I achieve this?
userId number_of_tasks captions
3 2 ["Kevin", "Elisa"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
JSON_GROUP_ARRAY()为每个用户创建字幕列表:
You can use
json_group_array()
aggregate function inside the subquery to create the list of captions for each user: