大家好,又见面了,我是你们的朋友全栈君。
点击打开):
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
最终的执行结果是一样的!
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/129288.html原文链接:https://javaforall.net