gpt4 book ai didi

mysql - SQL中同一列的多行计数

转载 作者:行者123 更新时间:2023-11-29 06:50:58 24 4
gpt4 key购买 nike

我正在尝试计算/添加具有相同列值的多行。

举个例子:

aid | uid | name              | region         | timestamp
17 | 43 | Max Payne | Western Europe | 1507677429
101 | 91 | Jeffrey Birchwood | North America | 1509586239
45 | 109 | Richard Branson | North America | 1509536026
167 | 133 | Soenke Tapaz | North America | 1510603831
23 | 431 | Sophie Turner | Western Europe | 1508166970
187 | 431 | Sophie Turner | Western Europe | 1511190350
19 | 431 | Sophie Turner | Western Europe | 1507887993
169 | 431 | Sophie Turner | Western Europe | 1510612773
161 | 431 | Sophie Turner | Western Europe | 1510574362
207 | 431 | Sophie Turner | Western Europe | 1511788946
145 | 431 | Sophie Turner | Western Europe | 1510138206
189 | 431 | Sophie Turner | Western Europe | 1511196429
8 | 445 | Faisal Riaz | North America | 1507583110
33 | 445 | Faisal Riaz | North America | 1509480510
12 | 445 | Faisal Riaz | North America | 1507659660
217 | 445 | Faisal Riaz | North America | 1511914655
7 | 445 | Faisal Riaz | North America | 1507560542
25 | 449 | Venkat Puri | North America | 1508509764
121 | 449 | Venkat Puri | North America | 1509704227
119 | 449 | Venkat Puri | North America | 1509704171
117 | 449 | Venkat Puri | North America | 1509703793
5 | 463 | Scott Jay | North America | 1507301571
21 | 463 | Scott Jay | North America | 1507910814
27 | 465 | Parker Tates | EEMA | 1509109957
29 | 467 | Vivian Bond | Western Europe | 1509465890
31 | 469 | Jean-Christophe Glachant | Western Europe | 1509474304
35 | 471 | Arnab Goswami | North America | 1509535475
37 | 473 | Matthias Toby | Western Europe | 1509535623
39 | 475 | Shubham Sawdhan | North America | 1509535625
41 | 477 | Martin Hoffmann | Asia | 1509535626

目标

我想做的是计算每个出现的region。因此我的结果是:

Region           | Count

Western Europe | 12
North America | 16
Asia | 1
EEMA | 1

谢谢

最佳答案

您只需使用group by:

select region, count(*)
from t
group by region;

我不知道你的查询与这个问题有什么关系。

关于mysql - SQL中同一列的多行计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47543989/

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