T-SQL open Window function

Source: Internet
Author: User

Open Window function over ()

Use one: sort order BY, Row_number

SELECT *, RANK () over (order by Chinese Desc) from score--Displays all data for the score table according to the sort order of English scores , and appends a column sort ordinal column ( can have a repeating number ).

SELECT *,row_number () over (order BY price desc) -Displays all data for the demand table based on the sort order of the prices, and appends a column of row number columns ( no repetition numbers ).
From Orders


Purpose Two: zoning partition by, combined with aggregation functions to summarize a part of the data

--The traditional statistical summary, which indicates that the entire data is zoned (that is, sum () is the sum of the entire table)
Select Name,SUM (count)
From Orders
  group by name

--using partition by to draw the area,sum () is the sum of the data after the zoned area .

SELECT *,SUM (Ocount) over (partition by oname)
From Tblorders

  

T-SQL open Window 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.