Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --1
- --fromDate -> Thu Jun 01 00:00:00 CEST 2017
- --toDate -> Sun Jun 25 23:59:00 CEST 2017
- --vehicleOwner -> -1
- --vehicleCategory -> 102984
- --gu_user_id -> 102079
- SELECT vehicle_owner_id,
- vo_vehicle_category_id,
- vehicle_category_name,
- description,
- vehicle_id,
- vehicle_name,
- date_day,
- (NVL(ru_install_hr,0) + hour_counter_begin) hour_counter_begin,
- (NVL(ru_install_hr,0) + hour_counter_end) hour_counter_end,
- ((NVL(ru_install_hr,0) +hour_counter_end) - (NVL(ru_install_hr,0) +hour_counter_begin)) daily_diff_hour_counter,
- (NVL(ru_install_km,0) + km_counter_begin) km_counter_begin,
- (NVL(ru_install_km,0) + km_counter_end) km_counter_end,
- ((NVL(ru_install_km,0) + km_counter_end) - (NVL(ru_install_km,0) + km_counter_begin)) daily_diff_km_counter
- FROM
- (
- SELECT v.vehicle_owner_id,
- v.vo_vehicle_category_id,
- voc.name AS vehicle_category_name,
- v.brand
- || ' '
- || v.model
- || ' '
- || v.color AS description,
- vd.vehicle_id,
- ltrim(rtrim(DECODE(v.company_nr, NULL, '', v.company_nr
- || ' - ')
- || v.numberplate)) AS vehicle_name,
- vd.date_day,
- v.ru_install_hr,
- ROUND(MIN(to_number(vd.hour_counter))/3600) hour_counter_begin,
- ROUND(MAX(to_number(vd.hour_counter))/3600) hour_counter_end,
- v.ru_install_km,
- MIN(vd.total_distance) km_counter_begin,
- MAX(vd.total_distance) km_counter_end
- FROM of_owner.vehicle_data vd,
- of_owner.vehicle v,
- of_owner.vo_vehicle_category voc,
- of_owner.gu_vehicle gv,
- of_owner.operation_center oc
- WHERE vd.vehicle_id = v.vehicle_id
- AND v.vehicle_id = gv.vehicle_id
- AND v.vo_vehicle_category_id = voc.vo_vehicle_category_id
- AND voc.vo_vehicle_category_id = decode(102984, -1, voc.vo_vehicle_category_id, 102984)
- AND voc.vehicle_owner_id = decode(-1, -1, voc.vehicle_owner_id,-1)
- AND gv.gui_user_id = 102079
- AND vd.date_day >= toutcdate( to_date ('01/06/2017 00:00','dd/MM/yyyy HH24:mi') , oc.timezone )
- AND vd.date_day <= toutcdate( to_date ('25/06/2017 00:00','dd/MM/yyyy HH24:mi') , oc.timezone )
- AND vd.vehicle_id IS NOT NULL -- not needed
- GROUP BY v.vehicle_owner_id,
- v.vo_vehicle_category_id,
- voc.name,
- v.brand
- || ' '
- || v.model
- || ' '
- || v.color,
- vd.vehicle_id,
- ltrim(rtrim(DECODE(v.company_nr, NULL, '', v.company_nr
- || ' - ')
- || v.numberplate)),
- vd.date_day,
- v.ru_install_hr,
- v.ru_install_km
- )
- UNION
- SELECT vehicle_owner_id,
- vo_vehicle_category_id,
- vehicle_category_name,
- description,
- vehicle_id,
- vehicle_name,
- date_day,
- (NVL(ru_install_hr,0) + hour_counter_end) hour_counter_begin,
- (NVL(ru_install_hr,0) + hour_counter_end) hour_counter_end,
- ((NVL(ru_install_hr,0) +hour_counter_end) - (NVL(ru_install_hr,0) +hour_counter_end)) daily_diff_hour_counter,
- (NVL(ru_install_km,0) + km_counter_end) km_counter_begin,
- (NVL(ru_install_km,0) + km_counter_end) km_counter_end,
- ((NVL(ru_install_km,0) + km_counter_end) - (NVL(ru_install_km,0) + km_counter_end)) daily_diff_km_counter
- FROM
- (SELECT v.vehicle_owner_id,
- v.vo_vehicle_category_id,
- voc.name AS vehicle_category_name,
- v.brand
- || ' '
- || v.model
- || ' '
- || v.color AS description,
- vd.vehicle_id,
- ltrim(rtrim(DECODE(v.company_nr, NULL, '', v.company_nr
- || ' - ')
- || v.numberplate)) AS vehicle_name,
- vd.date_day,
- v.ru_install_hr,
- ROUND(MIN(to_number(vd.hour_counter))/3600) hour_counter_begin,
- ROUND(MAX(to_number(vd.hour_counter))/3600) hour_counter_end,
- v.ru_install_km,
- MIN(vd.total_distance) km_counter_begin,
- MAX(vd.total_distance) km_counter_end
- FROM of_owner.vehicle_data vd,
- of_owner.vehicle v,
- of_owner.vo_vehicle_category voc,
- of_owner.gu_vehicle gv,
- of_owner.operation_center oc
- WHERE vd.vehicle_id = v.vehicle_id
- AND v.vehicle_id = gv.vehicle_id
- AND v.vo_vehicle_category_id = voc.vo_vehicle_category_id
- AND gv.gui_user_id = 102079
- AND vd.date_day >= toutcdate( to_date ('01/06/2017 00:00','dd/MM/yyyy HH24:mi') , oc.timezone ) - 60
- AND vd.date_day <= toutcdate( to_date ('25/06/2017 00:00','dd/MM/yyyy HH24:mi') , oc.timezone )
- AND voc.vo_vehicle_category_id = decode(102984, -1, voc.vo_vehicle_category_id, 102984)
- AND voc.vehicle_owner_id = decode(-1, -1, voc.vehicle_owner_id, -1)
- AND vd.vehicle_id IS NOT NULL -- not needed
- GROUP BY v.vehicle_owner_id,
- v.vo_vehicle_category_id,
- voc.name,
- v.brand
- || ' '
- || v.model
- || ' '
- || v.color,
- vd.vehicle_id,
- ltrim(rtrim(DECODE(v.company_nr, NULL, '', v.company_nr
- || ' - ')
- || v.numberplate)),
- vd.date_day,
- v.ru_install_hr,
- v.ru_install_km
- )
- WHERE vehicle_id NOT IN
- (SELECT v.vehicle_id
- FROM of_owner.vehicle_data vd,
- of_owner.vehicle v,
- of_owner.vo_vehicle_category voc,
- of_owner.gu_vehicle gv,
- of_owner.operation_center oc
- WHERE vd.vehicle_id = v.vehicle_id
- AND v.vehicle_id = gv.vehicle_id
- AND v.vo_vehicle_category_id = voc.vo_vehicle_category_id
- AND gv.gui_user_id = 102079
- AND vd.date_day >= toutcdate( to_date ('01/06/2017 00:00','dd/MM/yyyy HH24:mi') , oc.timezone )
- AND vd.date_day <= toutcdate( to_date ('25/06/2017 00:00','dd/MM/yyyy HH24:mi') , oc.timezone )
- AND voc.vo_vehicle_category_id = decode(102984, -1, voc.vo_vehicle_category_id, 102984)
- AND voc.vehicle_owner_id = decode(-1, -1, voc.vehicle_owner_id, -1)
- AND vd.vehicle_id IS NOT NULL -- not needed
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement