About SQL Server's record of how to remove duplicate values

Source: Internet
Author: User

This is one of the problems that you encounter in your daily work.

Dt_user_pay_record table
ID UserID Time Money
122014-3-2 2
222015-3-2 33
322011-9-5 5
452016-2-2 66
552015-4-4 77
Remove data
UserID Time Money
22015-3-2 33
52016-2-2 66
I want to take out the same UserID and time Max data.

Scenario 1:

SELECT * FROM (
Select ID, user_id, created, Pay_money,
Row_number () over (partition by user_id ORDER by created DESC) seq from dt_user_pay_record) tbl where seq =1

Scenario 2:

SELECT * FROM Dt_user_pay_record T1
Where NOT EXISTS (select 1 from Dt_user_pay_record T2
where t1.user_id=t2.user_id and t2.created>t1.created)

About SQL Server's record of how to remove duplicate values

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.