Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

tax type   date                  taxname    a1    a2    a3   a4 
--------- -------------------- ----------- ---- ------ ---- ----  
"No Tax";"2014-01-28 15:17:14";"Inclusive";0.00;132.00;0.00;132.00
"No Tax";"2014-01-29 12:45:02";"Inclusive";0.00;148.00;0.00;148.00
"No Tax";"2014-01-29 14:07:07";"Inclusive";0.00;180.00;0.00;180.00
"No Tax";"2014-01-29 14:17:42";"Inclusive";0.00;50.00;0.00;50.00
"No Tax";"2014-01-29 14:49:39";"Inclusive";0.00;185.00;0.00;185.00
"No Tax";"2014-02-01 11:00:19";"Inclusive";0.00;165.00;0.00;165.00
"No Tax";"2014-02-03 11:52:26";"Inclusive";0.00;66.00;0.00;66.00
"No Tax";"2014-02-03 13:37:09";"Inclusive";0.00;185.00;0.00;185.00
"No Tax";"2014-03-30 17:14:36";"Inclusive";0.00;37.00;0.00;37.00
"VAT 1";"2014-01-07 11:01:01";"Inclusive";1.00;29.70;0.30;30.00
"VAT 1";"2014-01-08 18:44:07";"Inclusive";1.00;178.22;1.78;180.00
"VAT 1";"2014-01-15 15:48:23";"Inclusive";1.00;69.50;0.70;70.20
"VAT 1";"2014-01-16 13:15:37";"Inclusive";1.00;24.75;0.25;25.00
"VAT 1";"2014-01-18 17:35:19";"Inclusive";1.00;247.52;2.48;250.00
"VAT 1";"2014-03-30 13:04:24";"Inclusive";1.00;49.50;0.50;50.00
"VAT 2";"2014-01-01 11:13:54";"Inclusive";2.00;233.33;4.67;238.00
"VAT 2";"2014-01-01 11:55:34";"Inclusive";2.00;98.04;1.96;100.00
"VAT 2";"2014-01-01 12:23:34";"Inclusive";2.00;490.20;9.80;500.00
"VAT 2";"2014-01-01 13:13:19";"Inclusive";2.00;26.47;0.53;27.00
"VAT 2";"2014-01-01 14:16:49";"Inclusive";2.00;93.33;1.87;95.20
"VAT 2";"2014-03-30 19:44:09";"Inclusive";2.00;284.31;5.69;290.00
"VAT 3";"2014-01-01 11:02:49";"Inclusive";5.50;246.45;13.55;260.00
"VAT 3";"2014-01-01 11:04:28";"Inclusive";5.50;184.83;10.17;195.00
"VAT 3";"2014-01-01 11:13:54";"Inclusive";5.50;227.49;12.51;240.00
"VAT 3";"2014-01-01 11:13:54";"Inclusive";5.50;244.93;13.47;258.40

I have this table.
As you can see tax type is having more then one value.
so what i want to do is i have to display the sum(a2) for each tax type
means i want the output like this
"No Tax";"2014-01-28 15:17:14";"Inclusive";0.00;50.000;0.00;700.00
"VAT 2";"2014-01-01 11:13:54";"Inclusive";200.00;244.93;13.47;258.40
"VAT 3";"2014-01-01 11:13:54";"Inclusive";800.00;244.93;13.47;258.40

Please tell me how to write the query

This is what i tried
SQL
select to_char(td.bill_date,'MM-dd-yyyy') as bill_date,td.tax_name,td.tax_type,td.tax_value, ((td.item_total) -(td.tax_amount)) as SaleValue, (td.tax_amount) as tax_amount, (td.item_total) as Total from tbl_transaction_details td join tbl_transaction_master tm on td.bill_no=tm.bill_no Where to_char(td.bill_date,'MM-dd-yyyy')>='03-01-2014' and to_char(td.bill_date,'MM-dd-yyyy')<='03-02-2014' and td.account='ABCD'  and td.menu='ABCD' and tm.card>0  group by td.tax_amount,td.item_total,td.bill_date,td.tax_name,td.tax_type,td.tax_value order by td.bill_date,td.tax_value ASC;

Please guys, need your help..
Posted
Updated 21-Apr-14 18:28pm
v3

Check with following query,
select Tax,Type,TaxName,SUM(a2) as total  from Table_1 group by Tax,Type,TaxName;
 
Share this answer
 
v2
Comments
[no name] 22-Apr-14 0:00am    
I tried group by clause but it's not working here
R-a-v-i-k-u-m-a-r 22-Apr-14 1:52am    
Don't use date field in group by, Because each row contains different values so you will not get required result.
[no name] 22-Apr-14 1:56am    
If i don't then it will give error like
column "td.bill_date" must appear in the GROUP BY clause or be used in an aggregate function
R-a-v-i-k-u-m-a-r 22-Apr-14 2:00am    
You have to calculate the aggregate in a sub-query and then join it with itself to get the additional columns you'd need to show.check the link http://stackoverflow.com/questions/19601948/must-appear-in-the-group-by-clause-or-be-used-in-an-aggregate-function
[no name] 22-Apr-14 2:04am    
How to do that in this particular query..??i checked the link you gave but didn't got anything..
Why group by clause is not working.....
This will be your solution
SQL
Select TaxType,TaxName,SUM(a2) as total  from Table_Name group by TaxType,TaxName,a2
 
Share this answer
 
v2
Comments
[no name] 22-Apr-14 1:02am    
That's what even i am not getting why it is not working..i shared the query also..have a look..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900