

SQL: Select the sum of each individual value of a column
source link: https://www.codesd.com/item/sql-select-the-sum-of-each-individual-value-of-a-column.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

SQL: Select the sum of each individual value of a column
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.
This is example data:
|-------|
| 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
Related Articles
T-SQL select the sum of each year, and plan next year
SQLAlchemy: Selecting a row for each distinct value in a column
ORACLE SQL: Select multiple rows according to different values in a column for the same key value in another column
SQL: select three rows for each separate value
Query Mysql for the sum based on a value in a column group by this column
I need to get the sum of all odd values in odd columns
PHP (SQL) select the name where id = more values
SQL select the first and last row according to another column (timestamp)
select the sum of the values: grouped by sign
Select the sum of the column with the highest value in the staff row
Query SQL Server to find the sum of 4 consecutive values
An algorithm to sort a list of values in n groups so that the sum of each group is as close as possible
Get the account from the tables and display the sum of each column
How do I calculate the sum of radio button values using jQuery?
Recommend
-
4
Sql select the last value advertisements I have the following SQL statement SELECT [Motor] ,[Time] FROM [logger].[dbo]....
-
8
DELETE DUPLICATE VALUE IN THE SAME COLUMN - SQL #sql Aug 31 ...
-
5
Increase by 1 for each column change in R advertisements Lets say I have the following data frame set.seed(123) df <- data.f...
-
5
SQL Select a row for each category type advertisements I've the data in my table in following format. id | p...
-
4
Sql - find the value of one column to find all other values of another column advertisements This is a SQL question, I wi...
-
6
[CSS] Select First Column of Table Updated: April 10, 2017 See the dem...
-
6
SQL Group with Most Recent Record EachSay you have a table with student test data. SELECT t.* FROM tests t ORDER BY t.student_id, t.taken_on
-
5
Digital LiteracyThe need to personalize fonts for each individual reader...
-
3
In this article, we will discuss different ways to select all columns of a Pandas dataFrame except one specified column. Table Of Contents what do you mean by DataFrame...
-
6
How to Find Average Marks of Each Student in SQL? ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK