我有如下表格
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查询实现此目的?
答案 0 :(得分: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
答案 1 :(得分:3)
听起来你只是想要
SELECT particular,
max(opening) opening,
max(transaction) transaction,
max(ending) ending
FROM your_table_name
GROUP BY particular
答案 2 :(得分:0)
假设交易,开始和结束仅对一行大于零,则以下内容将起作用
SELECT
particular
, MAX(opening) as opening
, MAX(transaction) as transaction
, MAX(ending) as ending
FROM
TBL_NAME
GROUP BY particular
一般来说,这个文档(oracle按功能分组)可能很有用:http://docs.oracle.com/cd/E17952_01/refman-5.5-en/group-by-functions.html#function_max