select distinct * from tablename
select count(distinct code1) from tablename where code1=1
select count(distinct code1) from tablename where code1=2

解决方案 »

  1.   

    后面的不知道是什么要求
    select distinct * from tablename order by code1,code2
      

  2.   

    MSSQLSERVER:
    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)
      

  3.   

    并且一起得到Count(Code1)=5,Count(Code2)=2
    是不是这样:select a.code1,count(code1) from (select distinct * from tablename) a