Skip to content

Instantly share code, notes, and snippets.

@snth
Last active August 5, 2024 13:02
Show Gist options
  • Save snth/83671aa81c73e33872a0da1f0bb898fb to your computer and use it in GitHub Desktop.
Save snth/83671aa81c73e33872a0da1f0bb898fb to your computer and use it in GitHub Desktop.
jazzTracks example in PRQL
# Try this for yourself at: https://prql-lang.org/playground/
let arr_agg = func x -> s"array_agg({x})"
let jazzTracks = (
from t=tracks
join g=genres (==genre_id && g.name=="Jazz")
select {t.*, genre=g.name}
)
from a=albums
join s=artists (==artist_id)
join j=jazzTracks (j.album_id==a.album_id)
group {AlbumTitle = a.title, Artist = s.name} (
aggregate {
JazzTracks=(arr_agg f"{{Name='{j.name}',UnitPrice={j.unit_price}}}")
}
)
sort Artist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment