0

我正在尝试创建 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

在此处输入图像描述

数据库图

4

2 回答 2

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)
于 2012-09-13T19:14:01.757 回答
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),
于 2012-09-13T19:15:42.633 回答