diff --git a/2.6.sql b/2.6.sql deleted file mode 100644 index 20d3761..0000000 --- a/2.6.sql +++ /dev/null @@ -1,8 +0,0 @@ -SELECT title,car_warehouse.id,COUNT(*) total_count FROM service_history -INNER JOIN car_warehouse ON service_history.car_id=car_warehouse.id -INNER JOIN car_models ON car_warehouse.model_id=car_models.id -WHERE (end_date <= NOW() - INTERVAL '1 year' -OR start_date <= NOW() - INTERVAL '1 year') -GROUP BY title,car_warehouse.id -HAVING COUNT(*) > 1 -ORDER BY total_count DESC \ No newline at end of file diff --git a/2.6_FINAL.sql b/2.6_FINAL.sql new file mode 100644 index 0000000..be23954 --- /dev/null +++ b/2.6_FINAL.sql @@ -0,0 +1,24 @@ +SELECT + car_models.title, + car_models.code, + car_warehouse.plate, + customers.first_name, + customers.last_name, + COUNT(car_models.code) as service_count +FROM + service_history + INNER JOIN car_warehouse ON service_history.car_id = car_warehouse.id + INNER JOIN customers ON car_warehouse.owner_id = customers.id + INNER JOIN car_models ON car_warehouse.model_id = car_models.id +WHERE + service_history.start_date <= date_trunc('year', now()) - interval '1 year' + OR + service_history.end_date <= date_trunc('year', now()) - interval '1 year' +GROUP BY + car_models.id, + car_warehouse.plate, + customers.id +HAVING + COUNT(car_models.code) > 1 +ORDER BY + service_count DESC