|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
任何规模的组织都可能受益于外包服务,并在一个标准化和优化的平台上统一其数据库管理任务。基于其本身的特性,DBaaS提供了敏捷和高效的数据库服务,它可以支持多变的需求。复制代码代码以下:
--行转列成绩
--创建yh境
CreateTableTEST
(DATESVarchar(6),
EMPNOVarchar(5),
STYPEVarchar(1),
AMOUNTInt)
--拔出
InsertTESTSelect200605,02436,A,5
UnionAllSelect200605,02436,B,3
UnionAllSelect200605,02436,C,3
UnionAllSelect200605,02436,D,2
UnionAllSelect200605,02436,E,9
UnionAllSelect200605,02436,F,7
UnionAllSelect200605,02436,G,6
UnionAllSelect200605,02438,A,7
UnionAllSelect200605,02438,B,8
UnionAllSelect200605,02438,C,0
UnionAllSelect200605,02438,D,3
UnionAllSelect200605,02438,E,4
UnionAllSelect200605,02438,F,5
UnionAllSelect200605,02438,G,1
GO
--y
--假如STYPE流动,能够@N
Select
DATES,
EMPNO,
SUM(CaseSTYPEWhenAThenAMOUNTElse0End)AsA,
SUM(CaseSTYPEWhenBThenAMOUNTElse0End)AsB,
SUM(CaseSTYPEWhenCThenAMOUNTElse0End)AsC,
SUM(CaseSTYPEWhenDThenAMOUNTElse0End)AsD,
SUM(CaseSTYPEWhenEThenAMOUNTElse0End)AsE,
SUM(CaseSTYPEWhenFThenAMOUNTElse0End)AsF,
SUM(CaseSTYPEWhenGThenAMOUNTElse0End)AsG
FromTEST
GroupByDATES,EMPNO
OrderByDATES,EMPNO
--假如STYPE不流动,用BZ句
Declare@SVarchar(1000)
Set@S=
Select@S=@S+,SUM(CaseSTYPEWhen+STYPE+ThenAMOUNTElse0End)As+STYPEFrom(SelectDistinctSTYPEFromTEST)AOrderBySTYPE
Set@S=SelectDATES,EMPNO+@S+FromTESTGroupByDATES,EMPNOOrderByDATES,EMPNO
EXEC(@S)
GO
--假如被转置的是数字范例的话,使用以下语句
DECLARE@SVARCHAR(1000)
SET@S=SELECTDATES,EMPNO
SELECT@S=@S+,[+STYPE+]=SUM(CASEWHENSTYPE=+STYPE+THENAMOUNTELSE0END)
FROM(SelectDistinctSTYPEFromTEST)AOrderBySTYPE
SET@S=@S+FROMTESTGROUPBYDATES,EMPNO
EXEC(@S)
假如是列转行的话间接UnionAll就能够了
比方:
citystylecolor46485052
长沙S6MF010021521221
长沙S6MF010022011221
下面到上面的模样
citystylecolorsizeqty
长沙S6MF01002152461
长沙S6MF01002152482
长沙S6MF01002152502
长沙S6MF01002152521
长沙S6MF01002201461
长沙S6MF01002201482
长沙S6MF01002201502
长沙S6MF01002201521
SelectCity,Style,Color,[46]FromTest
Unionall
SelectCity,Style,Color,[48]FromTest
Unionall
SelectCity,Style,Color,[50]FromTest
Unionall
SelectCity,Style,Color,[52]FromTest
就能够了根据Evans的调查报告,“MySQL的使用在未来将继续呈成长趋势。” |
|