项目月度报告和总计费时间

时间:2012-09-13 19:08:51

标签: sql sql-server-2008

我正在尝试创建sql语句,以显示每月低音项目花费的总时间可以有人帮助我 SQL查询

SELECT Projects.projectID,
        Projects.projectName,
        billingsTimes.actualTotalTime,
        billingsTimes.taskID,
        Tasks.taskName
  FROM Projects_tasks
       INNER JOIN Projects ON Projects_tasks.projectID = Projects.projectID
       INNER JOIN Tasks ON Projects_tasks.taskID = Tasks.taskID
       INNER JOIN billingsTimes ON Tasks.taskID = billingsTimes.taskID

enter image description here

DB图

2 个答案:

答案 0 :(得分:0)

这会有效吗?:

SELECT  Projects.projectID,
        Projects.projectName,
        SUM(billingsTimes.actualTotalTime),
        billingsTimes.taskID,
        Tasks.taskName, 
        MONTH(billingTimes.createdOn),
        YEAR(billingTimes.createdOn)
FROM    Projects_tasks
        INNER JOIN Projects ON Projects_tasks.projectID = Projects.projectID
        INNER JOIN Tasks ON Projects_tasks.taskID = Tasks.taskID
        INNER JOIN billingsTimes ON Tasks.taskID = billingsTimes.taskID
GROUP BY
        Projects.projectID,
        Projects.projectName,
        billingsTimes.taskID,
        Tasks.taskName, 
        MONTH(billingTimes.createdOn),
        YEAR(billingTimes.createdOn)

答案 1 :(得分:0)

select p.projectID,
    p.projectName,
    year(bt.createdOn) as Year,
    month(bt.createdOn) as Month,
    sum(bt.actualTotalTime) as TotalTime
from Projects_tasks pt
inner join Projects p on pt.projectID = p.projectID
inner join Tasks t on p.taskID = t.taskID
inner join billingsTimes bt on t.taskID = bt.taskID
group by p.projectID,
    p.projectName,
    year(bt.createdOn),
    month(bt.createdOn),