oracle中distinct的正確應用

來源:互聯網
上載者:User

table表有id、name兩個欄位:
有資料:
1、a;
2、b;
3、c;
4,c;
5、b
select distinct name from table;    ——>name    a    b    c
select distinct name, id from table    ——>id name 1 a  2 b  3 c  4 c  5 b(id與name都相同的才會被排除)
select id, distinct name from table    ——>報錯,distinct必須放在開頭
select *, count(distinct name) from table group by name    ——>1 a 1   2 b 1   3 c 1

group by 必須放在 order by 和 limit之前,不然會報錯

原文摘自:http://cache.baiducontent.com/c?m=9d78d513d99e01fc09b3c3690d67813d5812db3f6d91c7150ec3e54e84105c563667f4cb21351174c4b37d7070ae5d1baaae3928714562a09abb955798fed73f2fff76682042db1453c419d89a1b7adc76cd0fa3e84eb3edac678efd9282850f179d4e057883f096580409ca6ced1436e4a39c4a174810cdb7763aa1&p=882a9545d68c1fe604aa8e2d0214c6&newp=8f759a45d6c35afd1ab0c7710f41c4231610db2151d0d00e2d96ce&user=baidu&fm=sc&query=oracle+distinct+%D4%F5%C3%B4%D3%C3&qid=&p1=3

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.