Home >Backend Development >PHP Tutorial >MySQL (C API) VC example and code download (1) (3)_PHP tutorial

MySQL (C API) VC example and code download (1) (3)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:02:55709browse


4. Maximum sorting problem of query data (can only be written in one statement)

CREATE TABLE hard (qu char (11) ,co char (11) ,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 required query results are as follows:

qu co je

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

A 6 9

A 2 4

B 3 6

B 2 5

C 6 7

C 3 4

It is necessary to group by qu, and take the top 2 with the largest je in each group! !

And you can only use one 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. Looking for a SQL statement to delete duplicate records?

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

For example, there are id and name fields in table test

If there are records with the same name, only one will be left, and the rest will be deleted.

The content of name is variable, and the number of identical records is variable.

Is there such a sql statement?

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630991.htmlTechArticle4. Maximum sorting problem of query data (can only be written in one statement) CREATE TABLE hard (qu char (11 ) ,co char (11) ,je numeric(3, 0)) insert into hard values ​​('A','1',3) insert into h...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn