2017-05-24 25 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