user256034
user256034

Reputation: 4369

join with sum and group by

I have two tables. They're in a 1:N relationship.

Tasks - Id - Name

Report - Id - Time - TaskId -FK

I'd like to create a query which will sum the report time by a task.

I tried this,but its not working

SELECT NAME,SUM (TIME) FROM TASKS LEFT JOIN REPORT ON TASKS.ID = REPORT.TASKID                         
                GROUP BY TASKS.NAME

Its Oracle and with this query the time column is null in the result.

Upvotes: 0

Views: 360

Answers (1)

Tomalak
Tomalak

Reputation: 338228

SELECT
  NAME, 
  SUM( ISNULL(TIME, 0) ) SumOfTime /* Time could be NULL! */
FROM
  TASKS 
  LEFT JOIN REPORT ON TASKS.ID = REPORT.TASKID                         
GROUP BY
  TASKS.NAME

Upvotes: 1

Related Questions