Current location - Training Enrollment Network - Mathematics courses - An sql statement, find out the scores and total scores of all subjects of students according to their names, and rank them according to the total scores.
An sql statement, find out the scores and total scores of all subjects of students according to their names, and rank them according to the total scores.
Examples of sql statements that find out the scores and total scores of all subjects of students according to their names and rank them according to the total scores are as follows:

Choice? A. name,

(choose? B.scores? From where? table_score? b? Where is it? B.type=' math '? And then what? A.id=B.id)as? Math,

(choose? B.scores? From where? table_score? b? Where is it? B.type=' language'? And then what? A.id=B.id)as? China people,

(choose? B.scores? From where? table_score? b? Where is it? B.type=' English'? And then what? A.id=B.id)? As? English,

(choose? SUM(B.score)? From where? table_score? b? Where is it? A.id=B.id)? As? Sum fraction

From where? Table _ student? Answer? Order? bysum_score? DESC

The above sql statement first finds out each student's math, Chinese and English scores by combining the student table and the achievement table, and then passes the select? SUM(B.score)? From where? table_score? b? Where is it? A.id=B.id Find out the total score of each student.

Last course? bysum_score? DESC realizes flashback arrangement according to the total score.

Extended data

The sql statement above mainly focuses on the use of as keyword aliases. Using SQL, you can specify aliases for column and table names.

SQLAlias syntax of table

select column _ name from table _ name as alias _ name;

SQLAlias syntax for columns

select column _ nameASalias _ name from table _ name;

Alias instance: Alias with table name

Suppose we have two tables: "Persons" and "Product_Orders". We gave them nicknames "P" and "po" respectively.

Now, we're going to list all the orders for "JohnAdams".

We can use the following SELECT statement:

Select po. OrderID,p.LastName,p.FirstNameFROMPersonsASp,Product_OrdersASpoWHEREp。 Last name = Adams, first name = John.