Created
November 15, 2024 10:04
-
-
Save acro5piano/d3d540d286a0e5d02dd462cbccea023f to your computer and use it in GitHub Desktop.
Bringing PRQL into TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prql | |
.query() | |
.from('invoices') | |
.derive({ | |
transaction_fee: 0.8, | |
income: 'total - transaction_fee', | |
}) | |
.filter('income', '>', 5) | |
.filter('invoice_date', '>=', '@2010-01-16') | |
.group('customer_id', { | |
aggregate: { | |
sum_income: 'sum income', | |
ct: 'count customer_id', | |
}, | |
}) | |
.join('c', 'customers (==customer_id)') | |
.derive('name', f`{c.last_name}, {c.first_name}`) | |
.derive('db_version', s`version()`) | |
.select('c.customer_id', 'name', 'sum_income', 'ct', 'db_version') | |
.sort('-sum_income') | |
.take(1, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment