SQL:选择列中每个值的总和 [英] SQL: Select sum of each individual value of a column
本文介绍了SQL:选择列中每个值的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一列可以包含多个值.我想选择一个计数,每个离散值在整个集合中出现多少次.我觉得可能有一个明显的解决方案,但这使我望而却步.我将显示输入&预期的输出,希望它足够明显,您将了解.
There is a column that can have several values. I want to select a count of how many times each distinct value occurs in the entire set. I feel like there's probably an obvious solution but it's eluding me. I'll show input & expected output, hopefully it's obvious enough that you'll understand.
这是示例数据:
|-------|
| class |
|-------|
| 5 |
| 5 |
| 12 |
| 4 |
| 12 |
|-------|
这是我想要获得的输出:
This is the output I'm trying to get:
|-------|-------|
| class | count |
|-------|-------|
| 5 | 2 |
| 12 | 2 |
| 4 | 1 |
|-------|-------|
推荐答案
SELECT CLASS, COUNT (*)
FROM MYTABLE
GROUP BY CLASS
这篇关于SQL:选择列中每个值的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文