有一张日志表 _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;