diff --git a/project1/a.sql b/project1/a.sql index 8941e98..cf62d53 100644 --- a/project1/a.sql +++ b/project1/a.sql @@ -102,8 +102,8 @@ WHERE sig_id <> pk_id; -- #16.1.5 Get blocks with inputs that have outputs which have already been -- spent (double-spending) --- First, get outputs that have been doubly spent -CREATE OR REPLACE VIEW outputs_doubly_spent AS ( +-- First, get outputs that have more than one input +CREATE OR REPLACE VIEW outputs_multiple_inputs AS ( SELECT output_id FROM non_coinbase_inputs JOIN outputs USING(output_id) @@ -113,14 +113,14 @@ CREATE OR REPLACE VIEW outputs_doubly_spent AS ( -- Second, get corresponding input_id where the output was first spent CREATE OR REPLACE VIEW inputs_first_spent AS ( SELECT MIN(input_id) AS input_id, output_id - FROM outputs_doubly_spent + FROM outputs_multiple_inputs JOIN non_coinbase_inputs USING(output_id) GROUP BY output_id ); -- Third, combine to get invalid blocks INSERT INTO temporary_table SELECT block_id -FROM outputs_doubly_spent +FROM outputs_multiple_inputs JOIN non_coinbase_inputs USING(output_id) WHERE input_id NOT IN ( SELECT input_id