From 6a199273fc9a5baf79624a4896ca235d879a859c Mon Sep 17 00:00:00 2001 From: CrypthonicsException Date: Sun, 28 Nov 2021 05:14:56 +0300 Subject: [PATCH] Ex C,Part 2, Tasks 1-2 --- project1/c.sql | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/project1/c.sql b/project1/c.sql index 665d525..0354429 100644 --- a/project1/c.sql +++ b/project1/c.sql @@ -67,3 +67,51 @@ FROM tempRelations; DROP TABLE IF EXISTS temp_symmetry; DROP TABLE IF EXISTS tempRelations; + +-- exercise c (2) +CREATE TEMPORARY TABLE temp_clusters TABLE (id int, address int); + +INSERT INTO temp_clusters +SELECT id, address +FROM clusterAddresses(); + +DROP TABLE IF EXISTS max_value_by_entity; +DROP TABLE IF EXISTS min_addr_of_max_entity; +DROP TABLE IF EXISTS max_tx_to_max_entity; + +CREATE TABLE max_value_by_entity (value bigint); +CREATE TABLE min_addr_of_max_entity(addr int); +CREATE TABLE max_tx_to_max_entity(tx_id int); + +CREATE TEMPORARY TABLE temp_sum_values TABLE (id int, sum_values int); + +INSERT INTO temp_sum_values +SELECT id, SUM(value) as sum_values +FROM temp_clusters temp1 INNER JOIN ( + SELECT utxos.value, pk_id + FROM utxos + INNER JOIN outputs + USING (output_id) +) temp2 +ON temp1.address = temp2.pk_id +GROUP BY id; + +INSERT INTO max_value_by_entity +SELECT MAX(sum_values) +FROM temp_sum_values; + +INSERT INTO min_addr_of_max_entity +SELECT MIN(address) +FROM temp_clusters +INNER JOIN ( + SELECT id + FROM ( + SELECT id, MAX(sum_values) + FROM temp_sum_values + ) as temp + WHERE temp.sum_values = max_value_by_entity.value +) USING (id); + + + +