how to calculate unique column values in mysql

前端 未结 2 1090
粉色の甜心
粉色の甜心 2021-01-25 01:57

Here is my data

cardNo| userName| tablename| hours |  date 
1     |  a      |    a     |   12  |  12-06-2015 
1     |  a      |    a     |    5  |  11-06-2015 
2         


        
相关标签:
2条回答
  • 2021-01-25 02:38

    SELECT cardNo,userName, tablename, sum(hours) hours FROM Table_1 GROUP BY cardNo,userName,tablename

    0 讨论(0)
  • 2021-01-25 02:50

    It's simple SUM() with GROUP BY:

    SELECT cardNo,sum(hours) 
    FROM yourtable
    GROUP BY cardNo;
    

    I left it as an exercise for the OP to include userName and tablename columns into the query

    0 讨论(0)
提交回复
热议问题