sqlserver--sort

Source: Internet
Author: User

--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.