Skip to content

Commit

Permalink
pretty-format expensive SQL
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
jqnatividad committed May 29, 2024
1 parent 81601c6 commit 71cd173
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions scripts/expensive.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,43 @@ SELECT
A.Agency,
A.Borough,
COUNT(*) AS total_incidents,
SUM(CASE WHEN A."Complaint Type" LIKE 'Noise%' THEN 1 ELSE 0 END) AS noise_related_incidents,
SUM(CASE WHEN A.Status = 'Closed' THEN 1 ELSE 0 END) AS closed_incidents,
SUM(CASE WHEN A.Status != 'Closed' THEN 1 ELSE 0 END) AS open_incidents,
SUM(CASE WHEN POSITION('Water' IN A."Complaint Type") > 0 THEN 1 ELSE 0 END) AS water_related_incidents,
MAX(LENGTH(A."Complaint Type")) AS max_complaint_type_length,
SUM(CASE WHEN UPPER(A."Complaint Type") = UPPER(A."Complaint Type") THEN LENGTH(A."Complaint Type") ELSE 0 END) AS sum_complaint_type_lengths,
SUM(
CASE
WHEN A."Complaint Type" LIKE 'Noise%' THEN 1
ELSE 0
END
) AS noise_related_incidents,
SUM(
CASE
WHEN A.Status = 'Closed' THEN 1
ELSE 0
END
) AS closed_incidents,
SUM(
CASE
WHEN A.Status != 'Closed' THEN 1
ELSE 0
END
) AS open_incidents,
SUM(
CASE
WHEN POSITION('Water' IN A."Complaint Type") > 0 THEN 1
ELSE 0
END
) AS water_related_incidents,
MAX(LENGTH (A."Complaint Type")) AS max_complaint_type_length,
SUM(
CASE
WHEN UPPER(A."Complaint Type") = UPPER(A."Complaint Type")
THEN LENGTH (A."Complaint Type")
ELSE 0
END
) AS sum_complaint_type_lengths,
COUNT(DISTINCT A."Complaint Type") AS distinct_complaint_types
FROM
read_csv('NYC_311_SR_2010-2020-sample-1M.csv') A
GROUP BY
FROM
read_csv ('NYC_311_SR_2010-2020-sample-1M.csv') A
GROUP BY
A.Agency,
A.Borough
ORDER BY
ORDER BY
total_incidents DESC;

0 comments on commit 71cd173

Please sign in to comment.