SQL Server partition function partition by and group by difference Delete key field repeating column

Source: Internet
Author: User
Tags delete key

The partition by keyword is part of an analytic function that differs from an aggregate function (such as group by) in that it can return multiple records in a group, whereas aggregate functions generally have only one record that reflects the statistic value.

Partition by is used to group the result set, and if not specified, it takes the entire result set as a grouping.

Partition by differs from group by in that the former returns each piece of data in the group and can sort the grouped data. The latter can only return records for the data statistics values of the group after aggregation.

Usage: Select *,row_number () over (partition by Name order by score) as NewRow
From table

Delete a key field repeating column

@newtable---table name

@key-Self-added columns

@repeate---The key fields for duplicate checking

Delete ' [email protected]+ ' WHERE ' [email protected]+ ' In (select ' [E-mail protected]+ ' from (select *,rank () over (Partit Ion by ' [E-mail protected]+ ' ORDER by ' [email protected]+ '] as newrow from ' [email protected]+ ') NT where nt.newrow>1)

SQL Server partition function partition by and group by difference Delete key field repeating column

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.