大家好,又见面了,我是你们的朋友全栈君。
点击打开):
Create Table Students(Name varchar(10), Subject Nvarchar(10),Score int)
Insert into Students
Select 'Andy' ,'Chiness',round(60+40*rand(),0) Union all
Select 'Burgess' ,'Chiness',round(60+40*rand(),0) Union all
Select 'Ula' ,'Chiness',round(60+40*rand(),0) Union all
Select 'Lily' ,'Chiness',round(60+40*rand(),0) Union all
Select 'Demon' ,'Chiness',round(60+40*rand(),0) Union all
Select 'Andy' ,'Math',round(60+40*rand(),0) Union all
Select 'Burgess' ,'Math',round(60+40*rand(),0) Union all
Select 'Ula' ,'Math',round(60+40*rand(),0) Union all
Select 'Lily' ,'Math',round(60+40*rand(),0) Union all
Select 'Demon' ,'Math',round(60+40*rand(),0) Union all
Select 'Andy' ,'English',round(60+40*rand(),0) Union all
Select 'Burgess' ,'English',round(60+40*rand(),0) Union all
Select 'Ula' ,'English',round(60+40*rand(),0) Union all
Select 'Lily' ,'English',round(60+40*rand(),0) Union all
Select 'Demon' ,'English',round(60+40*rand(),0)
SELECT * FROM Students
PIVOT(MAX(SCORE) FOR Subject IN(Chiness,Math,English) ) AS PVT
点击打开)
SELECT * FROM (
SELECT * FROM Students
) a
PIVOT(MAX(SCORE) FOR Subject IN(Chiness,Math,English) ) AS PVT
最终的执行结果是一样的!
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/129288.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...