你應該四分之一的項目和empls這些項目的工作人員數量進行分組:
SELECT CASE
WHEN Start_Date >= '01-JAN-14' AND Start_Date <= '31-MAR-14' THEN 'Q1'
WHEN Start_Date >= '01-APR-14' AND Start_Date <= '30-JUN-14' THEN 'Q2'
WHEN Start_Date >= '01-JUL-14' AND Start_Date <= '30-SEP-14' THEN 'Q3'
WHEN Start_Date >= '01-OCT-14' AND Start_Date <= '31-DEC-14' THEN 'Q4'
END AS "Quarter",
COUNT(Proj_Number) Num, COUNT(Emp_Num) emp_count
FROM Project JOIN Assignment USING (Proj_Number) JOIN Employee USING (Emp_Num)
WHERE Start_Date >= '01-JAN-14' AND Start_Date <= '31-DEC-14'
GROUP BY "Quarter";
,你應該對每個項目花費的時間有不同的詢問
SELECT CASE
WHEN Start_Date >= '01-JAN-14' AND Start_Date <= '31-MAR-14' THEN 'Q1'
WHEN Start_Date >= '01-APR-14' AND Start_Date <= '30-JUN-14' THEN 'Q2'
WHEN Start_Date >= '01-JUL-14' AND Start_Date <= '30-SEP-14' THEN 'Q3'
WHEN Start_Date >= '01-OCT-14' AND Start_Date <= '31-DEC-14' THEN 'Q4'
END AS "Quarter",
Proj_Number ,AVG(Hours_Used) hours_spent
FROM Project JOIN Assignment USING (Proj_Number) JOIN Employee USING (Emp_Num)
WHERE Start_Date >= '01-JAN-14' AND Start_Date <= '31-DEC-14'
GROUP BY "Quarter" ,Proj_Number;
你可能想加入他們看到所有的信息在一個查詢
SELECT quarter.Quarter,quarter.Num as proj_count, quarter.emp_count,
proj.Proj_Number, proj.hours_spent
FROM (SELECT CASE
WHEN Start_Date >= '01-JAN-14' AND Start_Date <= '31-MAR-14' THEN 'Q1'
WHEN Start_Date >= '01-APR-14' AND Start_Date <= '30-JUN-14' THEN 'Q2'
WHEN Start_Date >= '01-JUL-14' AND Start_Date <= '30-SEP-14' THEN 'Q3'
WHEN Start_Date >= '01-OCT-14' AND Start_Date <= '31-DEC-14' THEN 'Q4'
END AS "Quarter",
COUNT(Proj_Number) Num, COUNT(Emp_Num) emp_count
FROM Project JOIN Assignment USING (Proj_Number) JOIN Employee USING (Emp_Num)
WHERE Start_Date >= '01-JAN-14' AND Start_Date <= '31-DEC-14'
GROUP BY "Quarter") quarter,
(SELECT CASE
WHEN Start_Date >= '01-JAN-14' AND Start_Date <= '31-MAR-14' THEN 'Q1'
WHEN Start_Date >= '01-APR-14' AND Start_Date <= '30-JUN-14' THEN 'Q2'
WHEN Start_Date >= '01-JUL-14' AND Start_Date <= '30-SEP-14' THEN 'Q3'
WHEN Start_Date >= '01-OCT-14' AND Start_Date <= '31-DEC-14' THEN 'Q4'
END AS "Quarter",
Proj_Number ,AVG(Hours_Used) hours_spent
FROM Project JOIN Assignment USING (Proj_Number) JOIN Employee USING (Emp_Num)
WHERE Start_Date >= '01-JAN-14' AND Start_Date <= '31-DEC-14'
GROUP BY "Quarter" ,Proj_Number) proj
WHERE quarter.Quarter = proj.Quarter