Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window function:  unexpected ROW_NUMBER #13828

Closed
BohuTANG opened this issue Nov 27, 2023 · 2 comments
Closed

window function:  unexpected ROW_NUMBER #13828

BohuTANG opened this issue Nov 27, 2023 · 2 comments
Assignees

Comments

@BohuTANG
Copy link
Member

Summary

Table setup:
https://github.com/BohuTANG/wizard/blob/main/checksb/sql/selects/bend/setup.sql

Error:


SQL: -- Query W4: Determine the first and last sale date for the first 10 customers SELECT customer_id, MIN(sale_date) OVER (PARTITION BY customer_id) AS first_purchase, MAX(sale_date) OVER (PARTITION BY customer_id) AS last_purchase FROM sales QUALIFY ROW_NUMBER() OVER (ORDER BY customer_id) <= 10; 

1005: error: 
  --> SQL:6:9
  |
3 | -- Query W4: Determine the first and last sale date for the first 10 customers
4 | SELECT customer_id, MIN(sale_date) OVER (PARTITION BY customer_id) AS first_purchase, MAX(sale_date) OVER (PARTITION BY customer_id) AS last_purchase
5 | FROM sales
6 | QUALIFY ROW_NUMBER() OVER (ORDER BY customer_id) <= 10;
  |         ^^^^^^^^^^ unexpected `ROW_NUMBER`, expecting `GROUP`, `ORDER`, `IGNORE_RESULT`, `INTERSECT`, `VALUES`, `OFFSET`, `WHERE`, `WINDOW`, `FORMAT`, `WITH`, `LIMIT`, `HAVING`, `EXCEPT`, `SELECT`, `UNION`, `,`, `(`, or `;`


Expected:
image

@BohuTANG BohuTANG added C-bug Category: something isn't working found-by-GPT4 labels Nov 27, 2023
@BohuTANG
Copy link
Member Author

Another case:

SQL: -- Query W7: Calculate the difference in net paid amount from the previous sale for the first 10 sales SELECT customer_id, sale_date, net_paid, LAG(net_paid, 1) OVER (PARTITION BY customer_id ORDER BY sale_date) - net_paid AS diff_from_prev_sale FROM sales QUALIFY ROW_NUMBER() OVER (ORDER BY customer_id, sale_date) <= 10; 

1005: error: 
  --> SQL:6:9
  |
3 | -- Query W7: Calculate the difference in net paid amount from the previous sale for the first 10 sales
4 | SELECT customer_id, sale_date, net_paid, LAG(net_paid, 1) OVER (PARTITION BY customer_id ORDER BY sale_date) - net_paid AS diff_from_prev_sale
5 | FROM sales
6 | QUALIFY ROW_NUMBER() OVER (ORDER BY customer_id, sale_date) <= 10;
  |         ^^^^^^^^^^ unexpected `ROW_NUMBER`, expecting `GROUP`, `ORDER`, `IGNORE_RESULT`, `INTERSECT`, `VALUES`, `OFFSET`, `WHERE`, `WINDOW`, `FORMAT`, `WITH`, `LIMIT`, `HAVING`, `EXCEPT`, `SELECT`, `UNION`, `,`, `(`, or `;`


@BohuTANG BohuTANG removed the C-bug Category: something isn't working label Nov 27, 2023
@ariesdevil
Copy link
Contributor

#13829

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants