Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to merge rows in SQL Oracle

I have table like below

PARTICULAR  OPENING TRANSACTION ENDING
Expense     5456456   0         0
Expense      0        1232131   0
Expense      0        0         123123

But I want to get the info like below

PARTICULAR  OPENING TRANSACTION ENDING
Expense     5456456  1232131    123123

Is it possible to achieve this using sql query?

like image 318
user3226313 Avatar asked Feb 14 '23 00:02

user3226313


2 Answers

You want to SUM it up, I guess!

SELECT particular, 
       SUM(opening) AS total_opening, 
       SUM(transaction) AS total_transaction,
       SUM(ending) AS total_ending
  FROM your_table
 GROUP BY particular
like image 166
Maheswaran Ravisankar Avatar answered Feb 17 '23 20:02

Maheswaran Ravisankar


It sounds like you just want

SELECT particular, 
       max(opening) opening, 
       max(transaction) transaction,
       max(ending) ending
  FROM your_table_name
 GROUP BY particular
like image 30
Justin Cave Avatar answered Feb 17 '23 18:02

Justin Cave