update report
This commit is contained in:
@ -79,25 +79,33 @@ class ReportsController extends Controller
|
||||
-- assign a trip_id by cumulative sum of trip_start
|
||||
SUM(trip_start) OVER (PARTITION BY vhc_id ORDER BY crt_d) AS trip_id
|
||||
FROM trips
|
||||
),
|
||||
agg AS (
|
||||
SELECT
|
||||
v.id,
|
||||
v.name,
|
||||
v.nopol1,
|
||||
vhc_id,
|
||||
trip_id,
|
||||
SUM(pre_milleage) AS mileage,
|
||||
MIN(a.crt_d) AS start,
|
||||
MAX(a.crt_d) AS finish,
|
||||
(SELECT fulladdress FROM t_gps_tracks_address WHERE master_id = MIN(a.id) LIMIT 1) AS startLoc,
|
||||
(SELECT fulladdress FROM t_gps_tracks_address WHERE master_id = MAX(a.id) LIMIT 1) AS finishLoc
|
||||
FROM t_vehicles v
|
||||
LEFT JOIN numbered a ON a.vhc_id = v.id
|
||||
WHERE
|
||||
v.dlt is null and trip_id != 0
|
||||
and if(? , v.id = ? , 1=1)
|
||||
GROUP BY v.id, a.trip_id
|
||||
)
|
||||
select
|
||||
v.id,
|
||||
-- coalesce(max(a.trip_id), 0) numOfTrip,
|
||||
-- SUM(pre_milleage) AS total_milleage,
|
||||
v.name, v.nopol1,
|
||||
vhc_id, trip_id,
|
||||
sum(pre_milleage) milleage, min(a.crt_d ) start, max(a.crt_d ) finish,
|
||||
(select fulladdress from t_gps_tracks_address where master_id = min(a.id) limit 1) startLoc,
|
||||
(select fulladdress from t_gps_tracks_address where master_id = max(a.id) limit 1) finishLoc
|
||||
FROM
|
||||
t_vehicles v
|
||||
left join numbered a on a.vhc_id = v.id
|
||||
WHERE
|
||||
v.dlt is null and trip_id != 0
|
||||
and if(? , v.id = ? , 1=1)
|
||||
GROUP BY v.id, a.trip_id
|
||||
ORDER BY v.id
|
||||
";
|
||||
SELECT
|
||||
*,
|
||||
SUM(mileage) OVER (PARTITION BY id) AS total_mileage,
|
||||
COUNT(trip_id) OVER (PARTITION BY id) AS total_trip
|
||||
FROM agg
|
||||
ORDER BY id, trip_id;
|
||||
";
|
||||
$d = [$from_date, $to_date, $vid, $vid];
|
||||
|
||||
$list = DB::select($q, $d);
|
||||
@ -229,7 +237,7 @@ class ReportsController extends Controller
|
||||
AND t.crt_d BETWEEN ? AND ?
|
||||
and if(? , tv.id = ? , 1=1)
|
||||
-- and t.speed > tvd.speed_limit
|
||||
having t.speed > tvd.speed_limit
|
||||
having t.speed >= tvd.speed_limit
|
||||
ORDER BY t.crt_d
|
||||
";
|
||||
$d = [$from_date, $to_date, $vid, $vid];
|
||||
|
||||
Reference in New Issue
Block a user