gpt4 book ai didi

MySQL分组汇总

转载 作者:行者123 更新时间:2023-11-29 01:25:20 25 4
gpt4 key购买 nike

在我的成员(member)表中,我想要“位置”1 - 7 中所有不同人员的摘要,以及有多少人在线和离线。

SELECT location, COUNT(*) FROM members GROUP BY location;

返回:

1 10  
2 5
3 4
4 12
5 6
6 3
7 19

我想要 COUNT 个状态为 0(离线)和状态为 1(在线)的成员。我该怎么做?

最佳答案

SELECT location, status, COUNT(*) FROM members GROUP BY location, status

作为一行:

SELECT
location,
COUNT(status) - SUM(status) as offline,
SUM(status) as online
FROM members
GROUP BY location

关于MySQL分组汇总,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2394194/

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