gpt4 book ai didi

mysql - MySQL GROUP BY 的问题

转载 作者:行者123 更新时间:2023-11-30 00:36:31 25 4
gpt4 key购买 nike

我正在尝试构建一个 SQL 查询,该查询应该输出所有用户事件,而不是求和或其他任何内容,而只是执行的每个事件的完整列表。

我遇到的问题是,我似乎无法让 GROUP BY 工作,以便打印出每个用户的事件。

SQLFiddle = http://sqlfiddle.com/#!2/5dce6/2

最终,我将构建这个 JSON 对象:

users: [{
userid: '1',
name: 'John',
activities: [{
activity_typeid: 6431,
time: "2013-01-01 00:00:00",
activity_weight: 20
}, {
activity_typeid: 6431,
time: "2013-01-01 00:00:00",
activity_weight: 20
}]
}, {
userid: '2',
name: Peter',
activities: [{
activity_typeid: 6431,
time: "2013-01-01 00:00:00",
activity_weight: 20
}
}]
}]

SQL:

SELECT activity_typeid, userid, time, activity_weight, activityname
FROM activity_entries
WHERE competitionid = '52a99783c5d6f'

最佳答案

SELECT activity_typeid, userid, time, activity_weight, activityname
FROM activity_entries
WHERE competitionid = '52a99783c5d6f' AND userid = someuserid

关于mysql - MySQL GROUP BY 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22127544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com