我现在有一个A表表里面有2个字段m(number),n(varchar2)下面是表的数据:  m    n
  1    天
  2    天
  2    小时
  4    小时select sum(m),n from A group by n  得到的数据是:  sum(m)    n
    3      天
    6      小时
问题来了:我现在只需要得到一条数据: m   m
 3   6也就是  按天和小时分组得到的m总数显示1条数据,而不是两条.求救: 如何做啊   感激不尽...

解决方案 »

  1.   

    http://topic.csdn.net/u/20110620/11/c06352http://topic.csdn.net/u/20110620/11/c06352cb-afa0-450f-9a2e-4d779133e472.htmlcb-afa0-450f-9a2e-4d779133e472.html
      

  2.   


    with table_a as(
         select 1 m,'天' n from dual
         union all
         select 2 m,'天' n from dual
         union all
         select 2 m,'小时' n from dual
         union all
         select 3 m,'小时' n from dual
    )select (select sum(m) from table_a t1 where t1.n = '天') day_count,
           (select sum(m) from table_a t1 where t1.n = '小时') hour_count
    from dual
      

  3.   

    抱歉:我没表述明白我是想用一条SQL来得到所需的数据
      

  4.   

     SELECT SUM(decode(n, '天', m)) "天", SUM(decode(n, '小时', m)) "小时"
       FROM a;
      

  5.   

    谢谢  老兵新手and找北京的工作   问题解决了