Exercise 2- UTXOS
This commit is contained in:
parent
f9f00cef80
commit
d509f430bf
30
project1/b.sql
Normal file
30
project1/b.sql
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
-- Clean tables
|
||||||
|
DROP TABLE IF EXISTS utxos;
|
||||||
|
DROP TABLE IF EXISTS number_of_utxos;
|
||||||
|
DROP TABLE IF EXISTS id_of_max_utxo;
|
||||||
|
CREATE TABLE utxos (output_id int, value bigint);
|
||||||
|
CREATE TABLE number_of_utxos (utxo_count int);
|
||||||
|
CREATE TABLE id_of_max_utxo (max_utxo int);
|
||||||
|
|
||||||
|
-- Get all utxos
|
||||||
|
|
||||||
|
INSERT INTO utxos
|
||||||
|
SELECT output_id, value
|
||||||
|
FROM outputs
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT * FROM inputs
|
||||||
|
WHERE inputs.output_id = outputs.output_id
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Get number of utxos
|
||||||
|
|
||||||
|
INSERT INTO number_of_utxos
|
||||||
|
SELECT COUNT(output_id) FROM utxos;
|
||||||
|
|
||||||
|
-- Get highest valued utxo
|
||||||
|
|
||||||
|
INSERT INTO id_of_max_utxo
|
||||||
|
SELECT output_id FROM utxos
|
||||||
|
ORDER BY value DESC
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user