(1) Remove duplicate records with the same two fields
delete from table a where exists (select 1 from table where datab=a.dataa and dataa=a.datab and dataa<a.datab)
(2) row to column
Name Course Score ---------- ---------- ----------- Zhangsan language 74 Zhang San Math 83 Zhang San Physics 93 Li Siyuwen 74 Li Si Math 84 Li Si Physics 94
select name, max(case course when 'language' then score else0end) language, max(case course when 'math' then fraction else0end) math, max(case course when 'physics' then fraction else0end) physics, sum (score) total score, cast(avg(score*1.0)asdecimal(18,2)) average score fromtb groupby name
Name, Chinese, Mathematics and Physics total score average ---------- ----------- ----------- ----------- ----------- Li Si 74 84 94 252 84.00 Zhang San 74 83 93 250 83.33