How would I do this in PRQL? - Most popular song #2947
Replies: 4 comments 5 replies
-
|
I don't understand what kind of aggregation you want to do as I don't have the ER diagram in my head, is this what you want to do? (I haven't tried to see if this actually works) from inv=invoices
join side:left item=invoice_items (==invoice_id)
join side:left t=tracks (item.track_id==t.track_id)
#filter inv.invoice_date >= @2010-01-01
#filter inv.total > 5
group {inv.billing_city, inv.billing_country} (
aggregate {
ct = count this,
}
sort {-ct}
take 1
) |
Beta Was this translation helpful? Give feedback.
-
|
@eitsupi @max-sixty Thanks again for your thoughts. I have spent a bunch of time thinking about this, and looking at SQL examples. But I'm still having trouble translating those back to a PRQL representation. I understand that you advise creating two queries with |
Beta Was this translation helpful? Give feedback.
-
|
@max-sixty @eitsupi @snth As I mentioned at yesterday's Dev Call, I would like to make the The query in the original post (above) joins the invoices, invoice_items, and tracks tables, and then groups by billing_city (and billing_country) and displays the count of each group. Running this in the playground shows:
I think what comes next is some kind of "inner query" that goes within the How do I express this in prql? Thanks. |
Beta Was this translation helpful? Give feedback.
-
|
This helps a lot. I hadn't been able to get it to work right either, and I now know it's not (solely) me. Other thoughts:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
@max-sixty @eitsupi I want to tune up the
introduction.prqlquery. The current (0.9.0) file is kind of meaningless (I have no idea what "useful function" it performs.) I would like to demonstrate something "real" using the Chinook database. I have set my hat on this question:What's the most popular song for each city in the database?
This query can illustrate joins, grouping, filtering, and other stuff in a seemingly premeditated way. I'm part-way there. So far, the query below isolates the city & country to show the count of the invoices.
But I need some kind of sub-query to count the
t.names within each group, then sort by that count, thentake 1.How can I express this in PRQL? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions