sql 去重關鍵字 distinct


單列去重:

mysql:

drop table test;
create table test(id int(4));
insert into test values(1),(2),(3),(4),(1),(2);
select count(distinct id) from test;
oracle:
drop table test;
create table test(id number(4));
insert all
into test values(1)
into test values(2)
into test values(3)
into test values(4)
into test values(1)
into test values(2)
select * from dual;
select count(distinct id) from test;


多列去重:

select deptno, job from emp; -- 結果有重復的

select distinct deptno, job from emp; -- deptno 和 job 兩個字段的值都相同,那么去重


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM