Ex C,Part 2, Tasks 1-2
This commit is contained in:
parent
3682fe295e
commit
6a199273fc
@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user