Reputation: 11
I want to get the sum of values of the rows with field_id 31 33 35 37 39 41.
This is the print screen from the table
I use this code to get the sum of all values of one field
SELECT field_id,
SUM(value)
FROM //table name
WHERE field_id = 23
GROUP BY field_id
How to get the sum of some fields values?
Upvotes: 0
Views: 47
Reputation: 23171
It sounds like you just need to specify all the ids you want in your WHERE clause:
SELECT field_id, sum(value)
FROM table
WHERE field_id IN (31,33,35,37,39,41)
GROUP field_id
Upvotes: 1
Reputation: 21657
If you want the total sum of those fields you could do:
SELECT SUM(value)
FROM table_name
WHERE field_id IN (31,33,35,37,39,41)
If you want it grouped by field_id you can do:
SELECT field_id,
SUM(value)
FROM table_name
WHERE field_id IN (31,33,35,37,39,41)
GROUP BY field_id
Upvotes: 1