MySQL (C API)VC執行個體及代碼下載 (1)(3)_PHP教程

來源:互聯網
上載者:User
4.查詢資料的最大排序問題(只能用一條語句寫)

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)

要求查詢出來的結果如下:

qu co je

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

A 6 9

A 2 4

B 3 6

B 2 5

C 6 7

C 3 4

就是要按qu分組,每組中取je最大的前2位!!

而且只能用一句sql語句!!!

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

5.求重複資料刪除記錄的sql語句?

怎樣把具有相同欄位的紀錄刪除,只留下一條。

例如,表test裡有id,name欄位

如果有name相同的記錄 只留下一條,其餘的刪除。

name的內容不定,相同的記錄數不定。

有沒有這樣的sql語句?

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

http://www.bkjia.com/PHPjc/630991.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630991.htmlTechArticle4.查詢資料的最大排序問題(只能用一條語句寫) CREATE TABLE hard (qu char (11) ,co char (11) ,je numeric(3, 0)) insert into hard values ('A','1',3) insert into h...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.