Cannot use group by and over(partition by) in the same query?

后端 未结 2 676
逝去的感伤
逝去的感伤 2020-12-30 04:01

I have a table myTable with 3 columns. col_1 is an INTEGER and the other 2 columns are DOUBLE. For example, col_1={

2条回答
  •  误落风尘
    2020-12-30 04:30

    I found the solution.

    I do not need to use OVER(PARTITION BY col_1) because it is already in the GROUP BY clause. Thus, the following query gives me the right answer:

    SELECT col_1, col_2, sum(Value) as sum_value
    from myTable GROUP BY col_1, col_2
    

    since I am already grouping w.r.t col_1 and col_2.

    Dave, thanks, I got the idea from your post.

提交回复
热议问题