Skip to content

Commit

Permalink
add 2 diffrent sql's
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishesh committed Sep 1, 2024
1 parent b92ab7a commit 73eef00
Show file tree
Hide file tree
Showing 6 changed files with 168,258 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Variables
DIALECT = duckdb
SQL_FILES = analyse.sql # Add more SQL files here if needed
SQL_FILES = analyse01.sql analyse02.sql # Add more SQL files here if needed

# Default target
all: lint
Expand Down
9 changes: 7 additions & 2 deletions analyse.sql → analyse01.sql
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,10 @@ ORDER BY
CASE
WHEN floor_area LIKE '<=%' THEN 0 -- Handling '<= 200'
WHEN floor_area LIKE '>%' THEN 3001 -- Handling '>3000'
ELSE CAST(SUBSTRING(floor_area FROM 1 FOR POSITION(' ' IN floor_area) - 1) AS INTEGER)
END;
ELSE
cast(
substring(
floor_area FROM 1 FOR position(' ' IN floor_area) - 1
) AS INTEGER
)
END;
109 changes: 109 additions & 0 deletions analyse02.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
CREATE TABLE ura AS
SELECT *
FROM read_csv_auto('dataset/to_merge/combined.csv', null_padding = true);

SELECT
"Floor Area (SQFT)" AS floor_area,
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '01') AS "1",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '02') AS "2",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '03') AS "3",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '04') AS "4",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '05') AS "5",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '06') AS "6",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '07') AS "7",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '08') AS "8",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '09') AS "9",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '10') AS "10",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '11') AS "11",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '12') AS "12",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '13') AS "13",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '14') AS "14",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '15') AS "15",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '16') AS "16",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '17') AS "17",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '18') AS "18",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '19') AS "19",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '20') AS "20",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '21') AS "21",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '22') AS "22",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '23') AS "23",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '24') AS "24",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '25') AS "25",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '26') AS "26",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '27') AS "27",
quantile_cont(
cast(replace("Monthly Rent ($)", ',', '') AS DOUBLE), 0.5
) FILTER (WHERE "Postal District" = '28') AS "28"
FROM
ura
GROUP BY
floor_area
ORDER BY
CASE
WHEN floor_area LIKE '<=%' THEN 0 -- Handling '<= 200'
WHEN floor_area LIKE '>%' THEN 3001 -- Handling '>3000'
ELSE
cast(
replace(
substring(
floor_area FROM 1 FOR position(' ' IN floor_area) - 1
),
',',
''
) AS INTEGER
)
END;
Loading

0 comments on commit 73eef00

Please sign in to comment.