Using SUM() without grouping the results

后端 未结 4 1856
别那么骄傲
别那么骄傲 2020-12-03 10:34

I already read (this), but couldn\'t figure out a way to implement it to my specific problem. I know SUM() is an aggregate function and it doesn\'t make sense n

4条回答
  •  春和景丽
    2020-12-03 11:07

    SELECT a.id, b.amount
    FROM table1 a
    CROSS JOIN
    (
        SELECT SUM(amount) amount FROM table1
    ) b
    

    You need to perform a cartesian join of the value of the sum of every row in the table to each id. Since there is only one result of the subselect (49), it basically just gets tacked onto each id.

提交回复
热议问题