SQL Server 2012-open Window functions

Source: Internet
Author: User

--open Window function: Further processing on the basis of the result set (aggregation operation)--over function, add a field to show maximum age select *, Max (stuage) over () Maxstuagefrom dbo. student;--over function, add a field to show total number of select *, COUNT (STUID) over () Stucountfrom dbo. student;--Partition by grouping statistics-based on gender groupings, statistics SELECT count (*) over (Partition by stusex), *from dbo. Student; --Based on class grouping, statistics, sorting SELECT COUNT (*) over (PARTITION by Class ORDER by Height), *from dbo. Student; --over function, add a field to show average height select *, avg (height) over () Ageheightfrom dbo. Student;--row_rumber () SELECT row_number () over (ORDER by Stuid DESC) RowNumber, *from dbo. Student--row_rumber () to achieve paging effect;     With T as (SELECT row_number () Up (ORDER by Stuid DESC) RowNumber, * from Dbo.  Student) SELECT * from T WHERE t.rownumber between 1 and 3;--rank () rank function, rank same, skip SELECT Rank () Over (ORDER by Height), *from dbo. Student;--dense_rank () ranking function, same rank do not skip select Dense_rANK () over (ORDER by Height), *from dbo. student;--NTILE () function, Parameters: Total number of records/division area = Array of each region, put the record ordinal into an array (average group) SELECT NTILE (3) over (ORDER by stusex), *from dbo .  Student;

  

SQL Server 2012-open Window functions

Related Article

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.