Changes between Version 5 and Version 6 of AdvancedDatabaseReports


Ignore:
Timestamp:
12/20/22 12:33:51 (2 years ago)
Author:
181085
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedDatabaseReports

    v5 v6  
    99{{{#!sql:
    1010SELECT d.driver_id, SUM(d.km_travelled) as km_travelled_with_driver,
    11 SUM(pay.total_sum_payed) as total_price_paid 
     11SUM(pay.total_sum_payed) as total_price_paid, SUM(d.km_travelled)/SUM(pay.total_sum_payed) as price_per_km
    1212FROM request r
    1313JOIN drive d ON r.request_id = d.request_id
     
    1515WHERE r.passenger_id = '77d9c766-e0c1-4e53-86d0-bafc3101a1ac' AND
    1616d.start_time between now() and now() - interval '2 months'
    17 GROUP BY d.driver_id
     17GROUP BY d.driver_id
     18ORDER BY price_per_km ASC
    1819}}}
     20
     21{{{#!sql:
     22SELECT dr.driver_id, dr.email, (CASE WHEN num_grades > 2 THEN AVG(de.grade) ELSE NULL END) as driver_grade, COUNT(*) as number_of_drives,
     23SUM(p.total_sum_payed) as total_money_made, COUNT(DISTINCT de.request_id) as number_of_different_requests,
     24COUNT(DISTINCT r.passenger_id) as number_of_different_passengers, (SUM(p.total_sum_payed))/COUNT(DISTINCT de.request_id) as average_money_per_request,
     25SUM(d.km_travelled) as total_km_travelled
     26FROM
     27driver dr
     28JOIN drive de ON dr.driver_id = de.driver_id
     29JOIN payment p ON de.drive_id = p.drive_id
     30LEFT JOIN request r ON de.request_id = r.request_id
     31GROUP BY dr.driver_id, dr.email
     32ORDER BY driver_grade DESC
     33}}