10

SQL: Select the sum of each individual value of a column

 3 years ago
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.
neoserver,ios ssh client

SQL: Select the sum of each individual value of a column

advertisements

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

I've got a pretty simple table with: Date, kWh It's got about 4 years of data. How can I produce a result set like: Year, Result 2010, 123211 2011, 123213 2012, 123211 2013, xxxxxx Where xxxx is a forecast for the year. The forecast would combine the

SQLAlchemy: Selecting a row for each distinct value in a column

I want to select one row each for each distinct value of a column. Here I want to perform it for col1: | ID | COL1 | COL2 | -------------------- | 1 | 0 | 0 | | 2 | 0 | 1 | | 3 | 1 | 11 | | 4 | 1 | 12 | | 5 | 1 | 16 | Which results in: | ID | COL1 |

ORACLE SQL: Select multiple rows according to different values ​​in a column for the same key value in another column

For example, I want to fetch a list of students who were enrolled in all the 4 semesters of MARCH, JUNE, SEPTEMBER, and NOVEMBER. But, I do not want to select students who missed enrolment in any of the above months and also were enrolled in semester

SQL: select three rows for each separate value

For each distinct Name, I want to select the first three rows with the earliest time_stamp (or smallest number in UNIXTIME). What is the correct query? Start Table: Name Log-in Time -------- ----------------- Don 05:30:00 Don 05:35:32 Don 07:12:43 Do

Query Mysql for the sum based on a value in a column group by this column

I am a mysql newbie here need some help with a sql query I cant quite figure out. I currently have a table Transact that contains something like this: Paytype Amount Date Cash 100.0 2013-08-01 Visa 50.00 2013-09-2 Check 50.00 2013-11-12 Cash 75.00 20

I need to get the sum of all odd values ​​in odd columns

This question already has an answer here: Calculating the sum of all odd array indexes 4 answers I have an array printing out only odd columns, and need to get the sum of all the odd values in odd columns. I create the variable total to do this and s

PHP (SQL) select the name where id = more values

I have table match (which contains "id, date, team1_id, team2_id") and table team (which contains "id, name") I need PHP or SQL code that will show name of team(from table team) WHERE "team1_id" and team2_id" = team.id .

SQL select the first and last row according to another column (timestamp)

Hello I am trying to do a select of certain elements on a table. here is what my table look like Time,UsrerId,Data. Now what i want to do is for the same userid i want the first and last Value of data according to the timestamp. Example: Time UserID

select the sum of the values: grouped by sign

I have a simple SQL table of the following format: date | value ============ 2010-01-01 | -54 2010-01-02 | 134 2010-01-03 | 73 With the following two SQL queries I can select the sum of values and distinguish between the sum of positive values and th

Select the sum of the column with the highest value in the staff row

I have this table: a b ----- 1 3 4 3 2 1 From where I would like to select the sum of whichever value is higher between a and b. I've tried with the following query but SUM() doesn't recognise the value I want him to sum. SELECT IF(a > b, a, b) AS nu

Query SQL Server to find the sum of 4 consecutive values

Can somebody help me in finding the sum of 4 consecutive values i.e rolling sum of last 4 values. Like: VALUE SUM 1 NULL 2 NULL 3 NULL 4 10 5 14 6 18 7 22 8 26 9 30 10 34 11 38 12 42 13 46 14 50 15 54 16 58 17 62 18 66 19 70 20 74 21 78 22 82 23 86 2

An algorithm to sort a list of values ​​in n groups so that the sum of each group is as close as possible

Basically I have a number of values that I need to split into n different groups so that the sums of each group are as close as possible to the sums of the others? The list of values isn't terribly long so I could potentially just brute force it but

Get the account from the tables and display the sum of each column

This is below data in Table2 ID2 | Count2 -----------+----------- 1345653 5 534140349 5 682527813 4 687612723 3 704318001 5 This is my below data in Table1 ID1 | Count1 -----------+----------- 1345653 4 704318001 4 If you see the above table this 134

How do I calculate the sum of radio button values ​​using jQuery?

I am trying to create a form with many groups containing many radio buttons. When the user selects a button, I would like to calculate the sum of each selected radio button value and show this sum to the user. I have found a plugin for jQuery which w

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK