读书人

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

发布时间: 2013-01-25 15:55:29 作者: rapoo

求一条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;

读书人网 >oracle

热点推荐