sql查询语句计算重复数据个数
如何写sql可以得到每一个行重复的个数呢?按照由大到小排列 展开
1、创建测试表,
create table test_count(id varchar2(20), value varchar2(20));
2、插入测试数据
insert into test_count values(1, 1);
insert into test_count values(2, 1);
insert into test_count values(3, 1);
insert into test_count values(4, 2);
insert into test_count values(6, 1);
insert into test_count values(7, 3);
insert into test_count values(8, 3);
insert into test_count values(9, 3);
insert into test_count values(10, 3);
commit;
3、查询表中全量数据,select t.*, rowid from test_count t;
4、编写sql,可以得到每一个value重复的个数,并按照由大到小排列;
select value, count(*) from test_count t group by value order by 2 desc
例子
personal表
id name
1 xm
2 xm
3 mx
统计personal表中name为xm的个数
select count(name) total from personal where name='xm'
结果
total
2
select count(*),字段名 from 表名
group by 字段名 having count(*)>1
select count(mypage) as s from deyebcount group by mypage order by mypage desc;