I've been trying to sum two different tax values amount from one table and my table is like below
我一直试图从一张表中总结两种不同的税额,我的表格如下
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
My output will be like:
我的输出将是:
total 5% amount is 5.75
total 14.5% amount is 16.25
Please help.
2 个解决方案
#1
0
Use SUM and GROUP By functions :
使用SUM和GROUP By函数:
SELECT Tax_percent , SUM(Tax_amount)
FROM your_table
GROUP BY Tax_percent
#2
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
#1
0
Use SUM and GROUP By functions :
使用SUM和GROUP By函数:
SELECT Tax_percent , SUM(Tax_amount)
FROM your_table
GROUP BY Tax_percent
#2
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