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