The SQL statement queries the data for the other column B maximum value of the same value for a column A

Source: Internet
Author: User

Problem Description:

There is a table file_info, with several fields, with 2 fields, filename (file name) and Filever (file version number).

Now the table data is this, the name of the FileName field may have the same (repeating), but when repeated, they correspond to the filever.

Query Result:

Requires querying out all data with the largest filever value when the filename field repeats.

The SQL statements are as follows:

1 SELECT *2  from(3     SELECT *, Row_number () Over(PARTITION byFileNameORDER  byFileverDESC) Num fromFile_info4     WHEREModuledataid='0b01dacc-27ec-4689-930b-088fc4e07a7a'5 ) T6 WHERET.num=1

Before and after the query effect is as follows:

The SQL statement queries the data for the other column B maximum value of the same value for a column A

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.