假如 oracle 数据库 A表中有一个字段B,
B
1,000.11
2,000.22
3,000
4.44现在 我想通过分组查询,将包含","的为一组,包含"."的为一组,查询出其中包含逗号和点号分别多少条的sql怎么写(分组查询)。

解决方案 »

  1.   

    SELECT COUNT(AA), COUNT(BB)
      FROM (SELECT (CASE
                     WHEN INSTR(B, ',') > 0 THEN  1
                     ELSE NULL
                   END) AA,
                   (CASE
                     WHEN INSTR(B, '.') > 0 THEN  2
                     ELSE NULL
                   END) BB
              FROM TABLE);
      

  2.   

    楼上思路不错
    实际上可以更简单select count(case when b like '%,%' then 1 end),
    count(case when b like '%.%' then 1 end)
    from a;
      

  3.   

    with tab as(
       select '1,000.11' as num from dual union all
       select '2,000.22' as num from dual union all
       select '3,000' as num from dual union all
       select '4.44' as num from dual 
    )
    select count((case when  instr(num,',',1,1) != 0 then 1 end)) as c1,count((case when  instr(num,',',1,1) = 0 then 1 end)) as c2   from tab
      

  4.   

    with a as 
    (select '1,000.11' col1 from dual
    union all
    select '2,000.22' col1 from dual
    union all
    select '3,000' col1 from dual
    union all
    select '4.44' col1 from dual)
    select count(case when instr(col1,',') > 0 then 1 end),
           count(case when instr(col1,'.') > 0 then 1 end)
     from a
      

  5.   

    select count(case when b like '%,%' then 1 end),count(case when b like '%.%' then 1 end)  from a
    -----so easy