数据分析笔记

 (1)去除两个字段相同的重复的记录

delete from 表 a where exists (select 1 from 表 where 数据b=a.数据a and 数据a=a.数据b and 数据a<a.数据b)

(2)行转列

姓名       课程       分数

---------- ---------- -----------

张三       语文        74

张三       数学        83

张三       物理        93

李四       语文        74

李四       数学        84

李四       物理        94

 

select姓名,

max(case课程when'语文'then分数else0end)语文,

max(case课程when'数学'then分数else0end)数学,

max(case课程when'物理'then分数else0end)物理,

sum(分数)总分,

cast(avg(分数*1.0)asdecimal(18,2))平均分

fromtb

groupby姓名

 

姓名       语文        数学        物理        总分        平均分

---------- ----------- ----------- ----------- -----------

李四        74          84          94          252         84.00

张三        74          83          93          250         83.33

 

猜你喜欢

转载自x10232.iteye.com/blog/2316232