当前位置:网站首页>Order by keyword syntax problems encountered in SQL Server learning

Order by keyword syntax problems encountered in SQL Server learning

2022-06-25 21:17:00 CSDN Q & A

background
At night sql Examples seen during the basic tutorial , Write it on the computer and keep reporting errors

select product_id,product_name,sale_price,        sum(sale_price) over(partition by product_type order by product_price) as current_sum    from product;select product_id,product_name,sale_price,        avg(sale_price) over(order by product_id) as current_avg    from product;
Operation results and error reporting contents

news 102, Level 15, state 1, The first 2 That's ok
'order' There are grammar errors nearby .
The error contents of both statements have been order There are grammatical errors at , But I don't know what's going on . I hope you can get an answer .




Take the answer :

Your mistake is inevitable , because COUNT(),SUM(),AVG(),MAX(MIN() All belong to aggregate functions , Aggregate windowing function can only use PARTITION BY Clause or without any statement ,ORDER BY Cannot be used with aggregate windowing function .  
Grammatical structure : Aggregate functions ( ) OVER ( [ <partition_by Clause > ] )

So you used order by It's wrong. , You can refer to this article for more information , I hope it helps you


原网站

版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202112229150465.html