当前位置: 代码迷 >> Oracle开发 >> 求一条sql语句,关于统计的解决方法
  详细解决方案

求一条sql语句,关于统计的解决方法

热度:37   发布时间:2016-04-24 07:08:37.0
求一条sql语句,关于统计的
有一张日志表 _log

需要的字段有  time:记录时间,cardId:身份证号码

身份证的 前俩位 是户籍地的代码 

要求统计 指定时间段内 每个户籍代码的总数

------解决方案--------------------

select substr(cardId,1,2),count(*)
from _log
where time between btime and etime
group by substr(cardId,1,2)

------解决方案--------------------
select xid, count(*)
  from (select t.*, substr(cardId, 1, 2) xid
          from _log t
         where time between 'YYYYMMDD' and 'YYYYMMDD')
 group by xid;
  相关解决方案