开发者

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.


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜