gpt4 book ai didi

mysql - 计算列中每一行的相同值

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

在我的 sql 中,我有一个如下所示的表。在该表中,我有 topicID 这不是主键,只是为了清楚起见。我正在努力编写一个脚本来计算表中相同的 topicID。

topicID  |  description |  date     |
| 1 | xyz | 2018-11-11 |
| 1 | xyz | 2018-11-11 |
| 2 | xyz | 2018-11-11 |
| 1 | xyz | 2018-11-11 |
| 3 | xyz | 2018-11-11 |
| 3 | xyz | 2018-11-11 |
| 2 | xyz | 2018-11-11 |
| 1 | xyz | 2018-11-11 |

例如:

topic Id    numberOfTime
1 4
2 2
3 3

最佳答案

你需要的是Group BY表达。尝试以下操作,

 select topicId as 'Topic Id' ,count(*) as 'Number of times' from my_table group by topicId

关于mysql - 计算列中每一行的相同值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49441888/

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