"SQL and the Pernicious Effect of Awkward Syntax" #1248
aljazerzen
started this conversation in
General
Replies: 2 comments 12 replies
-
As I see PRQL, this query can be decomposed exaclty as you suggest @max-sixty: from sales_by_date
derive [year = date | extract year, month = date | extract month]
group [year] (
# the group pipeline acts as it would start with
# from sales_of_some_specific_year
group [month] (
# and this inner group acts as it would receive:
# from sales_of_specific_month
aggregate monthly_sales = (sum month_sales)
# aggregate uses sum functions and implicitly applies
# select [monthly_sales]
)
# when group finishes with aggregate, it implicitly applies:
# select [month, monthly_sales]
# note that we are still within outer group
aggregate [
yearly_sales = sum total_sales,
by_month = array [month, monthly_sales]
]
# aggregate uses sum and array (which translates to array_agg)
# and implicitly applies: select [yearly_sales, by_month]
)
# group finished with aggregate, so it implicitly applies:
# select [year, yearly_sales, by_month] |
Beta Was this translation helpful? Give feedback.
7 replies
-
That's probably because he's doing analytics and copy-pastes results into a report in the end. So their exact format does not matter, since they are transformed by human™. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Beta Was this translation helpful? Give feedback.
All reactions