Mark hardy
Mark hardy

Reputation: 13

mySQL query to return totals of matching rows

This might be the first time I've ever had to ask a question! Usually find things already answered! anyhoo... here goes...

recordset has a job_id column, there might be 20 rows for that job_id, a numerical value posted in another column for each row. I'd like to be able to query the table where I can sum together all the numbers for each job_id. the resultant recordset will have however many rows, one row for each job_id, and a column with all the numerical values totalled for that job_id (hope that makes sense!)

Upvotes: 0

Views: 46

Answers (2)

feras salim
feras salim

Reputation: 46

try this query

SELECT job_id,SUM(numerical value) 
FROM table_name 
group by job_id

hope this help you

best regards

Upvotes: 0

user6307642
user6307642

Reputation:

You can use GROUP BY to group results by job_id and make the sum of numeric values for each group.

select job_id, sum(numeric_val) sum_numeric_val
from mytable
group by job_id

Upvotes: 1

Related Questions