Ex C,Part 2, Task 3

This commit is contained in:
CrypthonicsException 2021-11-28 05:42:34 +03:00
parent 6a199273fc
commit 847e482022

View File

@ -69,7 +69,7 @@ DROP TABLE IF EXISTS temp_symmetry;
DROP TABLE IF EXISTS tempRelations;
-- exercise c (2)
CREATE TEMPORARY TABLE temp_clusters TABLE (id int, address int);
CREATE TEMPORARY TABLE temp_clusters (id int, address int);
INSERT INTO temp_clusters
SELECT id, address
@ -83,7 +83,7 @@ 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);
CREATE TEMPORARY TABLE temp_sum_values (id int, sum_values int);
INSERT INTO temp_sum_values
SELECT id, SUM(value) as sum_values
@ -106,12 +106,27 @@ FROM temp_clusters
INNER JOIN (
SELECT id
FROM (
SELECT id, MAX(sum_values)
SELECT id, MAX(sum_values) as max_value
FROM temp_sum_values
) as temp
WHERE temp.sum_values = max_value_by_entity.value
) USING (id);
WHERE temp.max_value = max_value_by_entity.value
) as temp USING (id);
INSERT INTO max_tx_to_max_entity
SELECT tx_id
FROM outputs LEFT JOIN (
SELECT MAX(value) as value
FROM outputs LEFT JOIN (
SELECT address
FROM temp_clusters
INNER JOIN (
SELECT id
FROM (
SELECT id, MAX(sum_values) as max_value
FROM temp_sum_values
) as temp
WHERE temp.max_value = max_value_by_entity.value
) as join1 USING (id)
) as temp1 ON outputs.pk_id = temp1.address
) USING (value)