sqlserver--aggregation function

Source: Internet
Author: User

--1. Aggregate functions do not count null values

SELECT * FROM Tblstudent

Select COUNT (TSID) from tblstudent

Select AVG (tsage) from Tblstudent--avg () also does not count null values.

Select SUM (tsage) from Tblstudent--sum () for null values, considered to be

--2. If there is no manual group by grouping when using aggregate functions, the aggregate function will count the data in the entire table as a group

----------with conditional query--------------------

--select column

--from table

--where conditions

--inquire about a student who has not passed the exam (hypothesis: math or English, as long as there is a failure to pass the name of a non-pass) number

SELECT * FROM Tblscore

Select Tsid from Tblscore where tenglish<60 or tmath<60

--Search for male students aged between 30 years (inclusive and)

SELECT * FROM Mystudent

SELECT * from Mystudent where fage>=20 and fage<=30 and fgender= ' men '

SELECT * from Mystudent where Fage between and fgender= ' men '

--between...and ... In... Between, (closed interval, contains two endpoint values)

--check for male students aged between 30 years

--Query math score between 90 and all students

SELECT * from Tblscore where tmath between and 90

SELECT * FROM Tblstudent

--Check out all class IDs for those students who are 4,5

--19,1,27,86 SELECT * from Tblstudent where Tsclassid in (19,1,27,86)

SELECT * from tblstudent where tsclassid=3 or tsclassid=4 or tsclassid=5

SELECT * from Tblstudent where Tsclassid in (3,4,5)

--for in or or queries, if the criteria in the query are consecutive numbers, it is best to use >= <= or Between...and do not use or or in. Increase efficiency

SELECT * from Tblstudent where Tsclassid >=3 and tsclassid<=5

sqlserver--aggregation function

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.