mithrandie / csvq

SQL-like query language for csv
https://mithrandie.github.io/csvq
MIT License
1.5k stars 65 forks source link

window function issue #36

Closed alitrack closed 2 years ago

alitrack commented 4 years ago

issue

the following sql works on SQLite

SELECT sellerid, qty, round(1.0 * qty / (SUM(qty) OVER()),2) AS ratio_to_report  FROM  winsales

but got error on csvq

[L:1 C:51] syntax error: unexpected token "OVER"

have to change to

with stat as (
select NULLIF(SUM(qty),0) as qty_ttl from winsales
)
SELECT sellerid, qty, round(1.0 * qty / qty_ttl,2) AS ratio_to_report
FROM winsales, stat

data

salesid,dateid,sellerid,buyerid,qty,qty_shipped
30001,8/2/2003,3,b,10,10
10001,12/24/2003,1,c,10,10
10005,12/24/2003,1,a,30,    
40001,1/9/2004,4,a,40,  
10006,1/18/2004,1,c,10, 
20001,2/12/2004,2,b,20,20
40005,2/12/2004,4,a,10,10
20002,2/16/2004,2,c,20,20
30003,4/18/2004,3,b,15,
30004,4/18/2004,3,b,20, 
30007,9/7/2004,3,c,30,
mithrandie commented 4 years ago

In the current version, window functions can only be used as a field in SELECT clause or a key in ORDER BY clause. If you want to use it in any other way, you need to use inline tables defined in WITH clause or subqueries.

mithrandie commented 2 years ago

Analytic functions can be used as operands in expressions in version 1.17.1.