hmm, I get no result at all. switched the where back to the convert i had and it gave me the same numbers that i had before. the sum instead of the average. not sure why it's doing it :/
Main Topics
Browse All TopicsHi, I'm having a little difficulty with the logic of my query. If anyone could help that'd be great :)
select
case sso_ENTNRI
when 0 then 'Québec'
when 1 then 'Boucherville'
when 2 then 'Montréal'
when 3 then 'Ste-Julie'
end 'Entrepot',
sso_ENTNRI, sum(SSO_nbpal) as NB_Pal, sum(SSO_NBCs) as NB_Cs, sum(SSO_pds) as Poids
from stat_sommaire where convert(varchar,SSO_DATE,1
group by SSO_entnri
That returns the sum of all the pallets in that period, but how can i get the average sum. So that i get the average of a total for the warehouse. When I use Avg it gives me 332 for example (average number by client) instead of a total. and from what i saw i cant do avg(sum(SSO_nbpal)). Is there a way I can do this?
Audrey-Rose
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
if it were one single number that'd be what i would ask myself too. but its a sum. a sum in itself is a group of numbers added together. so i needed the average of it based on the dates so that i'd get all the numbers and get the average per day.
and i got it
SELECT CASE sso_ENTNRI
WHEN 0 THEN 'Québec'
WHEN 1 THEN 'Boucherville'
WHEN 2 THEN 'Montréal'
WHEN 3 THEN 'Ste-Julie'
END AS Entrepot,
sso_ENTNRI,
(SUM(SSO_nbpal))/@avg AS NB_Pal,
(SUM(SSO_NBCs))/@avg AS NB_Cs,
(SUM(SSO_pds)/@avg) AS Poids
FROM stat_sommaire
where convert(varchar,SSO_DATE,1
GROUP BY SSO_entnri
Business Accounts
Answer for Membership
by: BriCrowePosted on 2007-01-30 at 08:56:41ID: 18429032
SELECT CASE sso_ENTNRI
WHEN 0 THEN 'Québec'
WHEN 1 THEN 'Boucherville'
WHEN 2 THEN 'Montréal'
WHEN 3 THEN 'Ste-Julie'
END AS Entrepot,
sso_ENTNRI,
SUM(SSO_nbpal) AS NB_Pal,
SUM(SSO_NBCs) AS NB_Cs,
SUM(SSO_pds) AS Poids,
(SUM(SSO_nbpal) + SUM(SSO_NBCs) + SUM(SSO_pds)) / 3 AS AvgSum
FROM stat_sommaire
WHERE CONVERT(varchar, CONVERT(datetime, SSO_DATE, 112), 112) BETWEEN '2007/01/26' AND '2007/01/29'
GROUP BY SSO_entnri