sql - 如何从表中选择所有列并计数?
问题描述
我正在尝试选择表中的所有列top_teams_team
以及获取该hash_value
列的值的计数。此处的 sql 语句部分起作用,因为它返回两列,hash_value
并且total
. 我仍然希望它也给我表格的所有列。
select hash_value, count(hash_value) as total
from top_teams_team
group by hash_value
在下面的 sql 语句中,它给了我所有的列,但是显示了重复的 hash_value,这不是我想要的。我尝试输入distinct
关键字,但它不能正常工作,或者我没有把它放在正确的位置。
select *
from top_teams_team
inner join (
select hash_value, count(hash_value) as total
from top_teams_team
group by hash_value
) q
on q.hash_value = top_teams_team.hash_value
解决方案
我假设当您说:“但显示重复的 hash_value”时,您得到了重复的列
select q.hash_value, q.total, ttt.field1, ttt.field2, ttt.field3
from top_teams_team ttt
join (
select hash_value, count(hash_value) as total
from top_teams_team
group by hash_value
) q
on q.hash_value = top_teams_team.hash_value
推荐阅读
- ios - Xcode 无法在运行 iOS 13 的真实 iOS 设备上构建
- javascript - 在单击按钮时如何显示它已被选中并在表单提交时获取该按钮的 id
- mysql - 当且仅当在同一天发布时,将行显示在彼此之上
- java - Async AssertionError 没有使测试用例失败
- python-3.x - 我无法收到 0x11 之后的任何 HEX 数据
- php - 会计年度更改时自动重置发票编号
- webpack - runtimeChunk 的目的是什么?
- java - 对用户隐藏 Javafx 实现
- python - 如何编码字符串分类数据?
- elasticsearch - 在弹性搜索 5.6.0 中基于别名和模板翻转时面临错误