2014-01-23 140 views
4

行合併我的表像下面如何在SQL甲骨文

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

但我希望得到像下面

PARTICULAR OPENING TRANSACTION ENDING 
Expense  5456456 1232131 123123 

是否有可能的信息,以實現這一目標使用SQL查詢?

回答

3

這聽起來像你只是想

SELECT particular, 
     max(opening) opening, 
     max(transaction) transaction, 
     max(ending) ending 
    FROM your_table_name 
GROUP BY particular 
5

你想SUM它,我猜!

SELECT particular, 
     SUM(opening) AS total_opening, 
     SUM(transaction) AS total_transaction, 
     SUM(ending) AS total_ending 
    FROM your_table 
GROUP BY particular