2016-11-10 19 views
0

我需要选择交易列的总和,统计交易次数,全部由不同的客户ID进行计数。我已经尝试了一些嵌套查询以及类似以下内容:Oracle SQL根据不同客户标识交易

select distinct(customer_id), sum(tran_amt), count(tran) 
from tran_table 
inner join tender_table; 

tender_table有客户ID,所以我必须加入。

回答

0

您使用组的功能,但是你没有一个条款,我觉得这会给你正确的答案 “按组”:

SELECT CUSTOMER_ID,SUM(tran_amt),COUNT(TRAN) FROM tran_table INNER JOIN投标表格 GROUP BY CUSTOMER_ID;

0

我猜你想是这样的:

select te.customer_id, sum(t.tran_amt), count(*) 
from tran_table t inner join 
    tender_table te 
    on t.?? = te.?? 
group by te.customer_id; 

你需要join条件和group by条款。 ??用于join的列,您的问题未指定。

0

尝试这种情况:

选择tb_tran.customer_id,总和(tran_amt),计数(TRAN) 从tran_table tb_tran内加入tender_table tb_tender 上tb_tran.customer_id = tb_tender.customer_id 组由tb_tran.customer_id;