SUM(DISTINCT) Based on Other Columns

前端 未结 6 1329
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 11:23

I currently have a table that looks something like this:

+------+-------+------------+------------+
| id   | rate  | first_name | last_name  |
+------+-----         


        
6条回答
  •  执念已碎
    2020-12-10 12:17

    select sum (rate)
    from yourTable
    group by first_name, last_name
    

    Edit

    If you want to get all sum of those little "sums", you will get a sum of all table..

    Select sum(rate) from YourTable
    

    but, if for some reason are differents (if you use a where, for example) and you need a sum for that select above, just do.

    select sum(SumGrouped) from 
    (    select sum (rate) as 'SumGrouped'
        from yourTable
        group by first_name, last_name) T1
    

提交回复
热议问题