forked from Enriquefft/ProyectoDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.sql
31 lines (23 loc) · 821 Bytes
/
queries.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
set search_path to proyecto_1m, public;
select max(count), ruc
from (
select delivery_ruc_count.ruc, sum_del + sum_local as count
FROM
(SELECT ruc, count(ruc) AS sum_del FROM
(SELECT id AS delivery_id
FROM delivery_sells WHERE
EXTRACT(YEAR FROM date_time) = EXTRACT(YEAR FROM CURRENT_DATE)) AS delivery_sells
JOIN
company_delivery_sells
ON
company_delivery_sells.sell_id = delivery_sells.delivery_id GROUP BY ruc) AS delivery_ruc_count
FULL OUTER JOIN
(SELECT ruc, count(ruc) AS sum_local FROM
(SELECT id AS local_id
FROM local_sells WHERE
EXTRACT(YEAR FROM date_time) = EXTRACT(YEAR FROM CURRENT_DATE)) AS local_sells
JOIN
company_local_sells
ON
company_local_sells.sell_id = local_sells.local_id GROUP BY ruc) AS local_ruc_count
ON delivery_ruc_count.ruc = local_ruc_count.ruc) data group by ruc;