开发者

How to add duplicate rows using sql sum function

开发者 https://www.devze.com 2023-04-13 08:59 出处:网络
Few days ago, I came to a problem where I have to sum the value of some duplicate row in MySql & I\'ve tried some queries but they didn\'t work.

Few days ago, I came to a problem where I have to sum the value of some duplicate row in MySql & I've tried some queries but they didn't work.

Here is table data :-

card_id     tic_id  game_id     card_symbol     card_symbol_no  qty
1           6           1           C                   6        2
2           6           1           H                   7        6
3           6           1           C                   6        7

And My desired output is :-

card_id     tic_id  game_id     card_symbol     card_symbol_no  qty
1              6        1           C               6           (9)
2              6        1           H               7           (6)

some other given factor :-

1.) the "tic_id", & "game_id" is same.开发者_运维技巧


select 
  min(card_id) as card_id, 
  tic_id, 
  game_id, 
  card_symbol, 
  card_symbol_no, 
  sum(qty) as qty
from 
  yourTabel
group by 
  tic_id, 
  game_id, 
  card_symbol, 
  card_symbol_no
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号