MySQL (C API) VC instance and code download (1) (3) _php tutorial

Source: Internet
Author: User
4. Query the maximum sorting problem of data (only one statement is written)

CREATE TABLE Hard (qu Char (one), CO char (one), je Numeric (3, 0))

INSERT into hard values (' A ', ' 1 ', 3)

INSERT into hard values (' A ', ' 2 ', 4)

INSERT into hard values (' A ', ' 4 ', 2)

INSERT into hard values (' A ', ' 6 ', 9)

INSERT into hard values (' B ', ' 1 ', 4)

INSERT into hard values (' B ', ' 2 ', 5)

INSERT into hard values (' B ', ' 3 ', 6)

INSERT into hard values (' C ', ' 3 ', 4)

INSERT into hard values (' C ', ' 6 ', 7)

INSERT into hard values (' C ', ' 2 ', 3)

The results of the request query are as follows:

Qu Co JE

----------- ----------- -----

A 6 9

A 2 4

B 3 6

B 2 5

C 6 7

C 3 4

is to press Qu Group, each group to take JE the largest top 2!!

And only with a sentence of SQL statement!!!

SELECT * from Hard a Where JE in (select top 2 je from hard b where a.qu=b.qu order by JE)

5. Do you have an SQL statement to delete duplicate records?

How to delete records with the same field, leaving only one.

For example, there is a id,name field in the table test

If there is a name for the same record leaving only one, the rest is deleted.

The contents of name are variable and the same number of records is variable.

Is there such an SQL statement?

==============================

http://www.bkjia.com/PHPjc/630991.html www.bkjia.com true http://www.bkjia.com/PHPjc/630991.html techarticle 4. Query the maximum sorting problem of data (written in one statement only) CREATE TABLE hard (qu Char, CO char (single), je Numeric (3, 0)) insert into hard values (' A ', ' 1 ', 3) insert into H ...

  • 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.