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