每天會有定時任務,更新整個專案的所有資料得分,列名需要展示每個專案對應的年度得分,4個季度得分,12個月份得分。
表結構如下

目前我的sql
SELECT
p.ProjName,
p.ProjGUID as ProjectGUID ,
p.ProjCode,
Year 年度,
CASE
WHEN sum(case when Month=12 then YearScore else 0 end) != 0
THEN Convert(varchar, sum(case when Month=12 then YearScore else 0 end))
else '未結算年度得分'
END AS '年度得分',
CASE
WHEN sum(case when Month=03 then QuarterlyScore else 0 end) != 0
THEN Convert(varchar, sum(case when Month=03 then QuarterlyScore else 0 end))
else '未結算季度得分'
END AS '季度Q1',
CASE
WHEN sum(case when Month=06 then QuarterlyScore else 0 end) != 0
THEN Convert(varchar, sum(case when Month=06 then QuarterlyScore else 0 end))
else '未結算季度得分'
END AS '季度Q2',
CASE
WHEN sum(case when Month=09 then QuarterlyScore else 0 end) != 0
THEN Convert(varchar, sum(case when Month=09 then QuarterlyScore else 0 end))
else '未結算季度得分'
END AS '季度Q3',
CASE
WHEN sum(case when Month=12 then QuarterlyScore else 0 end) != 0
THEN Convert(varchar, sum(case when Month=12 then QuarterlyScore else 0 end))
else '未結算季度得分'
END AS '季度Q4',
sum(case when Month=01 then MonthScore else 0 end) as '1月指數',
sum(case when Month=02 then MonthScore else 0 end) as '2月指數',
sum(case when Month=03 then MonthScore else 0 end) as '3月指數',
sum(case when Month=04 then MonthScore else 0 end) as '4月指數',
sum(case when Month=05 then MonthScore else 0 end) as '5月指數',
sum(case when Month=06 then MonthScore else 0 end) as '6月指數',
sum(case when Month=07 then MonthScore else 0 end) as '7月指數',
sum(case when Month=08 then MonthScore else 0 end) as '8月指數',
sum(case when Month=09 then MonthScore else 0 end) as '9月指數',
sum(case when Month=10 then MonthScore else 0 end) as '10月指數',
sum(case when Month=11 then MonthScore else 0 end) as '11月指數',
sum(case when Month=12 then MonthScore else 0 end) as '12月指數'
FROM cms_CostIndex_ProjectTotalScore cpt
LEFT JOIN mdm_Project p on cpt.ProjectGUID=p.ProjGUID
WHERE Year = '2020' group by cpt.Year, p.ProjName, p.ProjGUID , p.ProjCode
查詢出來的結果

因為用了sum的聚合,它分數進行了累加。現在期待結果就是 取出最新一次更新時間的分數,這個表中的CreatedTime不知道怎么加入。
求助各位大神!
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/119189.html
標籤:疑難問題
上一篇:求解 QT 無法使用滑鼠移動事件 QMouseEvent
下一篇:Mysql—表資料之增刪改
