Oracle takes out the first data in a group ____oracle

Source: Internet
Author: User
OracelAnalysis function: You can remove the first (last) data in the group First_value () over (partition by ...)
Last_value () over (partition by ...) Create TableAtem
(
CO1 VARCHAR2(10),
CO2 INTEGER
) Insert intoAtem (CO1,CO2) Values(' A ', 1);
Insert intoAtem (CO1,CO2) Values(' A ', 2);
Insert intoAtem (CO1,CO2) Values(' A ', 3);
Insert intoAtem (CO1,CO2) Values(' A ', 4);
Insert intoAtem (CO1,CO2) Values(' A ', 1);
Insert intoAtem (CO1,CO2) Values(' B ', 1);
Insert intoAtem (CO1,CO2) Values(' B ', 2);
Insert intoAtem (CO1,CO2) Values(' C ', 1);
Insert intoAtem (CO1,CO2) Values(' d ', 1);
Insert intoAtem (CO1,CO2) Values(' d ', 2); Select distinct(First_value (A.CO2) over ( PARTITION byA.co1 Order byA.CO2)) asCo2,a.co1
fromAtem A//First_value (A.CO2) over ( PARTITION byA.co1 Order by A.CO2)///In the table by A.co1 group, and in the group A.co2 sorted, finally to get the data in the group A.co2

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.