2017-05-24 27 views
-4

我一直在试图总结两个不同的税收从一个表中的值量,我的表像下面如何汇总线性微分方程数值税单项金额

Sales table:  
Customer_id Tax_percent Tax_amount 
    100   5%   2.50 
    100   14.5%   6.75 
    101   5%   1.25 
    102   5%   2.00 
    101   14.5%   9.50 

我的输出将是这样的:

total 5% amount is 5.75 

total 14.5% amount is 16.25 

请帮忙。

+3

查找'sum'和'组by' – inarilo

+1

SELECT征税百分比,SUM(TAX_AMOUNT)销售 集团通过征税百分比 –

+1

哪个[DBMS]( https://en.wikipedia.org/wiki/DBMS)你在用吗? Postgres的?甲骨文? –

回答

0

使用SUM和GROUP BY功能:

SELECT Tax_percent , SUM(Tax_amount) 
FROM your_table 
GROUP BY Tax_percent 
0
declare @Salestable table(Customer_id int, Tax_percent numeric(5,2), Tax_amount numeric(5,2)) 
insert into @Salestable values( 100 ,   5  ,  2.50) 
insert into @Salestable values( 100 ,   14.5 ,  6.75) 
insert into @Salestable values( 101 ,   5  ,  1.25) 
insert into @Salestable values( 102 ,   5  ,  2.00) 
insert into @Salestable values( 101 ,   14.5 ,  9.50) 

select Tax_percent,sum(Tax_amount) from @Salestable group by Tax_percent