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