select distinct * from tablename
select count(distinct code1) from tablename where code1=1
select count(distinct code1) from tablename where code1=2
select count(distinct code1) from tablename where code1=1
select count(distinct code1) from tablename where code1=2
select distinct * from tablename order by code1,code2
select t1.code1,t1.code2,t3.num
from (select code1,code2
from tab
group by code1,code2)t1
left join
(select code1,max(code2) as code2,count(*) as num
from (select code1,code2
from tab
group by code1,code2) t2
group by code1)t3
on (t1.code1=t3.code1 and t1.code2=t3.code2)
是不是这样:select a.code1,count(code1) from (select distinct * from tablename) a