有一张日志表 _log需要的字段有  time:记录时间,cardId:身份证号码身份证的 前俩位 是户籍地的代码 要求统计 指定时间段内 每个户籍代码的总数

解决方案 »

  1.   


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

  2.   

    select xid, count(*)
      from (select t.*, substr(cardId, 1, 2) xid
              from _log t
             where time between 'YYYYMMDD' and 'YYYYMMDD')
     group by xid;
      

  3.   

    select houseHoldId, count(*) num
    from (
      select substr(cardId, 1, 2) houseHoldId
      from _log
      where time between v_beginTime and v_endTime
    ) T
    group by houseHoldId