Rittwick Banerjee
Rittwick Banerjee

Reputation: 135

How to add duplicate rows using sql sum function

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.

Upvotes: 2

Views: 4376

Answers (1)

GolezTrol
GolezTrol

Reputation: 116110

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

Upvotes: 5

Related Questions