No need for that. Here is some code that works perfectly in SQL.
;with Details(ChargeDescription, Charge, Weight)
as
(
select 'wrong address', 5.00, 2 union all
select 'wrong address', 5.00, 3 union all
select 'wrong weight', 3.00, 10
)
select ChargeDescription, SUM(Charge) as TotalCharges,
(SUM(Charge) / (select SUM(Charge) from Details)) * 100 as PercentOfTotal,
SUM(Weight) / (COUNT(*) * 1.0) as AvgWeight
from Details
group by ChargeDescription
order by ChargeDescription
Just to confirm I created an Access database with a table named Table1. I used the same column names and the same data.
Here is the query that worked perfectly in Access.
SELECT Description, SUM(Charge) as TotalCharges,
SUM(Charge) / (select SUM(Charge) from Table1) as PercentOfTotal,
SUM(Weight) / COUNT(*) as AvgWeight
from Table1
group by Description
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/