| 1 |
---input--- |
| 2 |
from invoices |
| 3 |
filter invoice_date >= @1970-01-16 |
| 4 |
derive { |
| 5 |
transaction_fees = 0.8, |
| 6 |
income = total - transaction_fees |
| 7 |
} |
| 8 |
filter income > 1 |
| 9 |
group customer_id ( |
| 10 |
aggregate { |
| 11 |
average total, |
| 12 |
sum_income = sum income, |
| 13 |
ct = count total, |
| 14 |
} |
| 15 |
) |
| 16 |
sort {-sum_income} |
| 17 |
take 10 |
| 18 |
join c=customers (==customer_id) |
| 19 |
derive name = f"{c.last_name}, {c.first_name}" |
| 20 |
select { |
| 21 |
c.customer_id, name, sum_income |
| 22 |
} |
| 23 |
derive db_version = s"version()" |
| 24 |
|
| 25 |
---tokens--- |
| 26 |
'from' Name.Variable |
| 27 |
' ' Text.Whitespace |
| 28 |
'invoices' Name.Variable |
| 29 |
'\n' Text.Whitespace |
| 30 |
|
| 31 |
'filter' Name.Variable |
| 32 |
' ' Text.Whitespace |
| 33 |
'invoice_date' Name.Variable |
| 34 |
' ' Text.Whitespace |
| 35 |
'>=' Operator |
| 36 |
' ' Text.Whitespace |
| 37 |
'@1970-01-16' Literal.Date |
| 38 |
'\n' Text.Whitespace |
| 39 |
|
| 40 |
'derive' Name.Variable |
| 41 |
' ' Text.Whitespace |
| 42 |
'{' Punctuation |
| 43 |
'\n ' Text.Whitespace |
| 44 |
'transaction_fees' Name.Variable |
| 45 |
' ' Text.Whitespace |
| 46 |
'=' Operator |
| 47 |
' ' Text.Whitespace |
| 48 |
'0.8' Literal.Number.Float |
| 49 |
',' Punctuation |
| 50 |
'\n ' Text.Whitespace |
| 51 |
'income' Name.Variable |
| 52 |
' ' Text.Whitespace |
| 53 |
'=' Operator |
| 54 |
' ' Text.Whitespace |
| 55 |
'total' Name.Variable |
| 56 |
' ' Text.Whitespace |
| 57 |
'-' Operator |
| 58 |
' ' Text.Whitespace |
| 59 |
'transaction_fees' Name.Variable |
| 60 |
'\n' Text.Whitespace |
| 61 |
|
| 62 |
'}' Punctuation |
| 63 |
'\n' Text.Whitespace |
| 64 |
|
| 65 |
'filter' Name.Variable |
| 66 |
' ' Text.Whitespace |
| 67 |
'income' Name.Variable |
| 68 |
' ' Text.Whitespace |
| 69 |
'>' Operator |
| 70 |
' ' Text.Whitespace |
| 71 |
'1' Literal.Number.Integer |
| 72 |
'\n' Text.Whitespace |
| 73 |
|
| 74 |
'group' Name.Variable |
| 75 |
' ' Text.Whitespace |
| 76 |
'customer_id' Name.Variable |
| 77 |
' ' Text.Whitespace |
| 78 |
'(' Punctuation |
| 79 |
'\n ' Text.Whitespace |
| 80 |
'aggregate' Name.Variable |
| 81 |
' ' Text.Whitespace |
| 82 |
'{' Punctuation |
| 83 |
'\n ' Text.Whitespace |
| 84 |
'average' Name.Function |
| 85 |
' ' Text.Whitespace |
| 86 |
'total' Name.Variable |
| 87 |
',' Punctuation |
| 88 |
'\n ' Text.Whitespace |
| 89 |
'sum_income' Name.Variable |
| 90 |
' ' Text.Whitespace |
| 91 |
'=' Operator |
| 92 |
' ' Text.Whitespace |
| 93 |
'sum' Name.Function |
| 94 |
' ' Text.Whitespace |
| 95 |
'income' Name.Variable |
| 96 |
',' Punctuation |
| 97 |
'\n ' Text.Whitespace |
| 98 |
'ct' Name.Variable |
| 99 |
' ' Text.Whitespace |
| 100 |
'=' Operator |
| 101 |
' ' Text.Whitespace |
| 102 |
'count' Name.Function |
| 103 |
' ' Text.Whitespace |
| 104 |
'total' Name.Variable |
| 105 |
',' Punctuation |
| 106 |
'\n ' Text.Whitespace |
| 107 |
'}' Punctuation |
| 108 |
'\n' Text.Whitespace |
| 109 |
|
| 110 |
')' Punctuation |
| 111 |
'\n' Text.Whitespace |
| 112 |
|
| 113 |
'sort' Name.Variable |
| 114 |
' ' Text.Whitespace |
| 115 |
'{' Punctuation |
| 116 |
'-' Operator |
| 117 |
'sum_income' Name.Variable |
| 118 |
'}' Punctuation |
| 119 |
'\n' Text.Whitespace |
| 120 |
|
| 121 |
'take' Name.Variable |
| 122 |
' ' Text.Whitespace |
| 123 |
'10' Literal.Number.Integer |
| 124 |
'\n' Text.Whitespace |
| 125 |
|
| 126 |
'join' Name.Variable |
| 127 |
' ' Text.Whitespace |
| 128 |
'c' Name.Variable |
| 129 |
'=' Operator |
| 130 |
'customers' Name.Variable |
| 131 |
' ' Text.Whitespace |
| 132 |
'(' Punctuation |
| 133 |
'==' Operator |
| 134 |
'customer_id' Name.Variable |
| 135 |
')' Punctuation |
| 136 |
'\n' Text.Whitespace |
| 137 |
|
| 138 |
'derive' Name.Variable |
| 139 |
' ' Text.Whitespace |
| 140 |
'name' Name.Variable |
| 141 |
' ' Text.Whitespace |
| 142 |
'=' Operator |
| 143 |
' ' Text.Whitespace |
| 144 |
'f' Literal.String.Affix |
| 145 |
'"' Literal.String.Double |
| 146 |
'{' Literal.String.Interpol |
| 147 |
'c' Name.Variable |
| 148 |
'.' Operator |
| 149 |
'last_name' Name.Variable |
| 150 |
'}' Literal.String.Interpol |
| 151 |
', ' Literal.String.Double |
| 152 |
'{' Literal.String.Interpol |
| 153 |
'c' Name.Variable |
| 154 |
'.' Operator |
| 155 |
'first_name' Name.Variable |
| 156 |
'}' Literal.String.Interpol |
| 157 |
'"' Literal.String.Double |
| 158 |
'\n' Text.Whitespace |
| 159 |
|
| 160 |
'select' Name.Variable |
| 161 |
' ' Text.Whitespace |
| 162 |
'{' Punctuation |
| 163 |
'\n ' Text.Whitespace |
| 164 |
'c' Name.Variable |
| 165 |
'.' Operator |
| 166 |
'customer_id' Name.Variable |
| 167 |
',' Punctuation |
| 168 |
' ' Text.Whitespace |
| 169 |
'name' Name.Variable |
| 170 |
',' Punctuation |
| 171 |
' ' Text.Whitespace |
| 172 |
'sum_income' Name.Variable |
| 173 |
'\n' Text.Whitespace |
| 174 |
|
| 175 |
'}' Punctuation |
| 176 |
'\n' Text.Whitespace |
| 177 |
|
| 178 |
'derive' Name.Variable |
| 179 |
' ' Text.Whitespace |
| 180 |
'db_version' Name.Variable |
| 181 |
' ' Text.Whitespace |
| 182 |
'=' Operator |
| 183 |
' ' Text.Whitespace |
| 184 |
's' Literal.String.Affix |
| 185 |
'"' Literal.String.Double |
| 186 |
'version()' Literal.String.Double |
| 187 |
'"' Literal.String.Double |
| 188 |
'\n' Text.Whitespace |