数据库表:GPS_LOG,索引为车牌号
特点    :同一辆车会用N条不用时间段上传的GPS数据
查询目标:从GPS_LOG表获取某一时间段上传过GPS的数据的车辆车牌号码,相同车牌号只去一条。
方法:Select distinct t.plateno from GPS_LOG t Where t.indate between P_StartTime and P_EndTime;
      执行时间需要几十分钟。原因:加了distinct后索引无效。
对比:Select t.plateno  from GPS_LOG t Where t.indate between P_StartTime and P_EndTime;
      执行结果小于10S,但结果集不是查询要求,车牌号重复。
求助:如题?

解决方案 »

  1.   

    select distinct q.plateno from
    (Select plateno from GPS_LOG Where indate between P_StartTime and P_EndTime) q;
      

  2.   

    Select t.plateno  from GPS_LOG t Where t.indate between P_StartTime and P_EndTime; 
    and exists(select 1 form gps_log a where t.plateno=a.plateno and p.rowid<a.rowid)
      

  3.   

    楼上的我发帖前已试过
    方法一:
    Select t.plateno  from Gps_Log_Hazmat t 
    Where t.indate>sysdate-0.01 
    and exists(select a.plateno from gps_log_hazmat a
    where t.plateno=a.plateno and t.rowid <a.rowid);Select t.plateno  from Vehcile_Hazmat t ---注表Vehcile_Hazmat是车辆基础信息表,车牌号唯一
    Where exists(select a.plateno from gps_log_hazmat a
    where t.plateno=a.plateno and t.rowid <a.rowid);
    执行效果一样没有提高,还是几十分钟。
      

  4.   

    方法一:
    Select t.plateno  from Gps_Log_Hazmat t
    Where Where t.indate between P_StartTime and P_EndTime
    and exists(select a.plateno from gps_log_hazmat a
    where t.plateno=a.plateno and t.rowid <a.rowid);
    方法二:
    Select t.plateno  from Vehcile_Hazmat t ---注表Vehcile_Hazmat是车辆基础信息表,车牌号唯一
    Where exists(select a.plateno from gps_log_hazmat a
    where t.plateno=a.plateno 
    and a.indate between P_StartTime and P_EndTime);
    执行效果一样没有提高,还是几十分钟。
      

  5.   

    Select t.plateno from GPS_LOG t Where t.indate between P_StartTime and P_EndTime
    group by t.plateno 
      

  6.   

    8楼
    Select t.plateno from GPS_LOG t Where t.indate between P_StartTime and P_EndTime 
    group by t.plateno  
    的sql语句有问题,执行肯定不通过,
    group by t.plateno 没有distinct的功能
      

  7.   

    已经解决
    方法:给GPS_LOG表按日期分区存储数据,这样保证每各分区的数据量大概在2千万条。然后给INDATAE列建索引。
    执行效率小于8S