开发者

join with sum and group by

开发者 https://www.devze.com 2023-02-25 13:50 出处:网络
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 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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消