Skip to content

Commit

Permalink
add attempt at p1 solution, to test later
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Jul 11, 2024
1 parent 2b6e2e6 commit e72d807
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions sql/p0001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Parameters:
Return: INT
Purpose:
Detailed explanation of the function which includes:
- Function business logic
- Transformation rules
- Here is a bit more text.
*/
CREATE FUNCTION function_name ()
RETURNS INT
AS
BEGIN
-- SQL statements to define the function logic
CREATE TABLE IF NOT EXISTS threes ( value INT );
CREATE TABLE IF NOT EXISTS fives ( value INT );
CREATE TABLE IF NOT EXISTS fifteens ( value INT );
DECLARE @i INT = 0;

WHILE @i < 1000;
BEGIN
SET @i = @i + 3;
INSERT INTO threes VALUES ( @i );
END

SET @i = 0;
WHILE @i < 1000;
BEGIN
SET @i = @i + 5;
INSERT INTO fives VALUES ( @i );
END

DECLARE @result INT = SELECT SUM(value) FROM threes;
SET @result = @result + SELECT SUM(value) FROM fives;
SET @result = @result - SELECT SUM(value) FROM threes JOIN fives WHERE threes.value = fives.value;
DELETE threes;
DELETE fives;
DELETE fifteens;
RETURN @result;
-- Return statement indicating the result of the function
END;

0 comments on commit e72d807

Please sign in to comment.