diff --git a/3_b.sql b/3_b.sql index e24c3a9..86857de 100644 --- a/3_b.sql +++ b/3_b.sql @@ -4,27 +4,22 @@ DROP TYPE IF EXISTS temp_type; CREATE TYPE temp_type AS ( title character(60), - code character(60), - plate plate_num, - first_name character(60), - last_name character(60), + id numeric, service_count bigint ); CREATE OR REPLACE FUNCTION cursor_example() RETURNS SETOF temp_type AS $$ DECLARE - sample_cursor CURSOR FOR SELECT car_models.title, - car_models.code, - car_warehouse.plate, customers.first_name, - customers.last_name, COUNT(car_models.code) as service_count + sample_cursor CURSOR FOR 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 customers ON car_warehouse.owner_id = customers.id INNER JOIN car_models ON car_warehouse.model_id = car_models.id - GROUP BY car_models.id, car_warehouse.plate, customers.id - HAVING COUNT(car_models.code) > 1 - ORDER BY service_count DESC; + 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; results temp_type; BEGIN OPEN sample_cursor; diff --git a/JDBC_Example/.idea/workspace.xml b/JDBC_Example/.idea/workspace.xml index 7e21f6f..edc5b29 100644 --- a/JDBC_Example/.idea/workspace.xml +++ b/JDBC_Example/.idea/workspace.xml @@ -15,11 +15,9 @@ - - - - - + + + @@ -279,9 +277,7 @@ - - - + @@ -289,19 +285,15 @@ - - - + - - - - - + + + diff --git a/JDBC_Example/src/com/papei/database/Main.java b/JDBC_Example/src/com/papei/database/Main.java index 323e0be..77a4688 100644 --- a/JDBC_Example/src/com/papei/database/Main.java +++ b/JDBC_Example/src/com/papei/database/Main.java @@ -1,7 +1,6 @@ package com.papei.database; import java.sql.*; -import java.util.Properties; public class Main { diff --git a/thanos_queries/2f.sql b/thanos_queries/2f.sql index 62974b0..be23954 100644 --- a/thanos_queries/2f.sql +++ b/thanos_queries/2f.sql @@ -10,6 +10,10 @@ FROM 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,