select substr(id,1,3),count(*) from tableA group by substr(id,1,3)要求id必须是字符型,如果不是的话,最好用to_char转换一下

解决方案 »

  1.   

    select distinct substr(id,1,3) from table_name;
      

  2.   

    那简单了select substr(b.id,1,3),count(*) from 
    (elect a.id id, a.name name from tableA a group by id) b
    group by substr(b.id,1,3)你看看好用不?
      

  3.   

    select 少了一个字母select substr(b.id,1,3),count(*) from 
    (select a.id id, a.name name from tableA a group by id) b
    group by substr(b.id,1,3)
      

  4.   

    哦,原来可以这样,根据你的灵感,我知道了:select substr(b.id,1,3),count(*) from 
    (select distinct  a.id id name from tableA a ) b
    group by substr(b.id,1,3)
      

  5.   

    应该是:select substr(b.id,1,3),count(*) from 
    (select distinct  a.id id name from tableA a ) b
    group by substr(b.id,1,3)
      

  6.   

    应该是:select substr(b.id,1,3),count(*) from 
    (select distinct  a.id id from tableA a ) b
    group by substr(b.id,1,3)
      

  7.   

    上面对于字符串的情况已经介绍很详细了
    下面接受ID 是NUMBER的情况select floor(id/100) as qh, count(*) sl
    from tableA
    group by qhfloor(a)   --返回<=a的最小整数
      

  8.   

    题没看清楚
    select a.floor(id/100) as qh, a.count(*) sl
    from (select distinct id from tableA) a
    group by qh