Skip to content

Commit

Permalink
Use default query for 3_b
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanos Paravantis committed May 6, 2018
1 parent f400c29 commit 40d0e7c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
19 changes: 7 additions & 12 deletions 3_b.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 8 additions & 16 deletions JDBC_Example/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion JDBC_Example/src/com/papei/database/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.papei.database;

import java.sql.*;
import java.util.Properties;

public class Main
{
Expand Down
4 changes: 4 additions & 0 deletions thanos_queries/2f.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 40d0e7c

Please sign in to comment.