--order By column name
SELECT * FROM Tblstudent
--Sort by age, descending order
SELECT * from Tblstudent ORDER BY tsage Desc--Descending sort
--Sort by age, ascending order
SELECT * from Tblstudent ORDER BY tsage ASC--Sort Ascending
SELECT * from Tblstudent ORDER by Tsage--The default is ascending sort
SELECT * from Tblscore ORDER BY Tmath Desc
SELECT * from Tblscore ORDER by Tenglish
--Query the top name with the highest math scores
Select Top 5 * from Tblscore ORDER BY Tmath Desc
--Get the last one with the lowest math scores
Select Top 5 * from Tblscore ORDER by Tmath ASC
--If the top is not a number, but an expression be sure to use () to enclose the expression.
Select Top (2*2) * from Tblscore ORDER BY Tmath Desc
--will query out the bar data.
Select top percent * from Tblscore ORDER BY Tmath Desc
--Get the youngest student
SELECT * FROM Mystudent
Select Top 5 * from Mystudent ORDER by Fage ASC
--Get the oldest percent of students (percent)
Select top percent * from mystudent ORDER BY Fage Desc
--the aggregate function defaults to the data in the entire table as a "group" before it is counted.
SELECT * FROM Newperson
--Statistics of the sum of the ages of all
Select SUM (age) as a sum from Newperson
--Count the total number of records in the current table
Select COUNT (*) from Newperson
--Calculating the mean age
Select
Mean age = (select SUM (age) as the sum of the ages from Newperson) *1.0/(SELECT COUNT (*) from Newperson)
--Calculating the oldest
Select Max (age) from Newperson
--The youngest
Select min from Newperson
--Calculate Average Avg
Select AVG (age*1.0) from Newperson
sqlserver--sort