Oracle queries data, where only one of the specified fields is repeated (Tutorial), the oracle Field

Source: Internet
Author: User

Oracle queries data, where only one of the specified fields is repeated (Tutorial), the oracle Field

Oracle Database, scenario: The data in the table (customer-Clerk) is not completely duplicated, but some fields in multiple data records may be duplicated. I want to obtain qualified records in the table, but the customer id and customer name in these records must be unique.

If I want to find out all the customers that "Feng Dongmei" is responsible for, but because she belongs to multiple departments, this table stores different departments-different customers corresponding to different personnel, so there will be duplicate data, so what should I do if I want to remove duplicates and get a complete record?

I tried distinct myself, but distinct can only expose repeated fields, so there is no way to complete the record; it is not implemented by using group by. Multi-party search, the contribution of SQL is as follows:

Select s. * from

(Select t. *, row_number () over (partition by customid order by customid) as group_idx

From base_custom_to_saler t where t. salername like '% Feng Dongmei %' and t. entryid = 9) s

Where s. group_idx = 1

Row_number ()... over (partition by... order ...) The logic is to group, sort, and retrieve data for fields that meet certain characteristics.

The result is as follows:

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.