Bootstrap

oracle 连续日期数据统计

 -- 取 用户ID 连续3天以上的记录

-- 数据库存的是“5/1/2015 16:26:43 ” 要转化 to_char(B.start_time,'yyyymmdd')

-- 获得用户ID

 SELECT C.user_id  FROM
(SELECT B.user_id, (MAX (to_char(B.start_time,'yyyymmdd')) - MIN (to_char(B.start_time,'yyyymmdd'))+1) as DAYS
FROM (SELECT A.*, TO_NUMBER(to_char(A.start_time,'yyyymmdd') - ROWNUM)as DAYS
FROM (
   SELECT user_id,  to_date(to_char(start_time,'yyyymmdd'),'yyyymmdd') as start_time ,min(score)as MI
 FROM drivereport where to_char(start_time,'yyyymmdd') >='20150501' and to_char(start_time,'yyyymmdd') <= '20150511'
  GROUP BY user_id, to_char(start_time,'yyyymmdd') ORDER BY user_id, to_char(start_time,'yyyymmdd')
   ) A  ) B
GROUP BY B.user_id, B.DAYS) C
WHERE C.DAYS > 2 order by c.user_id asc

;