SQL Server 實現數據的行列轉換 並且分組

SQL Server 實現數據的行列轉換 並且分組


select t1.UserNo,t1.Pad_Num,t2.EmployeeName,count(t1.Pad_Num) AS cnt
 into #temp_pad from tb_pad as t1
left join tb_Employee as t2 on t2.EmployeeNo = t1.UserNo
where CONVERT(CHAR(10), T1.RecordDate, 120)  between ''' + @beginDate + ''' and ''' + @endDate + '''
group by t1.UserNo, t1.Pad_Num,t2.EmployeeName


select EmployeeName AS ''姓名'',
 max(case when Pad_Num= ''1'' then cnt else 0 end) 非常滿意,
 max(case when Pad_Num= ''7'' then cnt else 0 end) 滿意,
 max(case when Pad_Num= ''2'' then cnt else 0 end) 基本滿意,
 max(case when Pad_Num= ''3'' then cnt else 0 end) 不滿意
from #temp_pad 
group by EmployeeName

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章