The SQL statement that identifies the student's grades and overall scores and the total score according to the person's name
/*
CREATE TABLE Student Table (
Study number nvarchar (+) NULL,
Name nvarchar (+) null)
CREATE TABLE Score Table (
Study number nvarchar (+) NULL,
Account nvarchar (+) NULL,
Score decimal (10,1) null
)
INSERT INTO student table values (' 101 ', ' Zhang San ')
INSERT INTO student table values (' 104 ', ' John Doe ')
INSERT INTO student table values (' 107 ', ' Harry ')
INSERT INTO student table values (' 111 ', ' any six ')
Insert INTO score table values (' 101 ', ' language ', 90)
Insert INTO score table values (' 101 ', ' Math ', 91)
Insert INTO score table values (' 101 ', ' English ', 92)
Insert INTO score table values (' 101 ', ' Politics ', 93)
Insert INTO score table values (' 104 ', ' language ', 96)
Insert INTO score table values (' 104 ', ' math ', 70)
Insert INTO score table values (' 104 ', ' English ', 80)
Insert INTO score table values (' 104 ', ' politics ', 92)
Insert INTO score table values (' 107 ', ' language ', 70)
Insert INTO score table values (' 107 ', ' math ', 100)
Insert INTO score table values (' 107 ', ' English ', 90)
Insert INTO score table values (' 107 ', ' Politics ', 98)
Insert INTO score table values (' 111 ', ' language ', 97)
Insert INTO score table values (' 111 ', ' math ', 90)
Insert INTO score table values (' 111 ', ' English ', 99)
Insert INTO score table values (' 111 ', ' Politics ', 99)
*/
Select A. Name
, (select B. score from table B where b. Subject = ' language ' and A. Study number =b) as language
, (select B. score from score table B where b. Subject = ' mathematics ' and A. =b No.) as Mathematics
, (select B. score from score table B where b. Subject = ' English ' and A. Study number =b) as English
, (select B. score from score table B where b. Subject = ' politics ' and A. =b number) as politics
, (select SUM (b. Score) from the score table B where A. Study number =b.) as Total
From student table A order by Total DESC
Query Result:
SQL b table is sorted by a table ID sum