失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > mssql行转列 列转行

mssql行转列 列转行

时间:2023-11-03 08:09:05

相关推荐

mssql行转列 列转行

一、行转列:

select max(case OptionKey when 'A' then OptionCont else null end) A,max(case OptionKey when 'B' then OptionCont else null end) B,max(case OptionKey when 'C' then OptionCont else null end) C,max(case OptionKey when 'D' then OptionCont else null end) D,...TitleCodefrom T_Optiongroup by TitleCode

二、列转行:

select * from(select ExamRecordId,TitleCode,max(oa) OptionKey,max(A) OptionCont from V_Titlegroup by ExamRecordId,TitleCodeunion allselect ExamRecordId,TitleCode,max(ob) OptionKey,max(B) OptionCont from V_Titlegroup by ExamRecordId,TitleCodeunion allselect ExamRecordId,TitleCode,max(oc) OptionKey,max(C) OptionCont from V_Titlewhere C is not nullgroup by ExamRecordId,TitleCodeunion allselect ExamRecordId,TitleCode,max(od) OptionKey,max(D) OptionCont from V_Titlewhere D is not nullgroup by ExamRecordId,TitleCode) Taborder by TitleCode,ExamRecordId

看看大佬的文章昂

如果觉得《mssql行转列 列转行》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。