Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A problem with averages
Message
De
10/08/2012 14:16:16
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Titre:
A problem with averages
Divers
Thread ID:
01550308
Message ID:
01550308
Vues:
80
Hi -

Here is an interesting problem. Suppose I have a statement like this:
update SegmentAverages set 
p1 = (SELECT AVG(p1) FROM allcounts WHERE (allcounts.count_id = SegmentAverages.count_id and allcounts._day <3)),
p2 = (SELECT AVG(p2) FROM allcounts WHERE (allcounts.count_id = SegmentAverages.count_id and allcounts._day <3)),
p3 = (SELECT AVG(p3) FROM allcounts WHERE (allcounts.count_id = SegmentAverages.count_id and allcounts._day <3)),
p4 = (SELECT AVG(p4) FROM allcounts WHERE (allcounts.count_id = SegmentAverages.count_id and allcounts._day <3)),
p5 = (SELECT AVG(p5) FROM allcounts WHERE (allcounts.count_id = SegmentAverages.count_id and allcounts._day <3)),
p6 = (SELECT AVG(p6) FROM allcounts WHERE (allcounts.count_id = SegmentAverages.count_id and allcounts._day <3)),
p7 = (SELECT AVG(p7) FROM allcounts WHERE (allcounts.count_id = SegmentAverages.count_id and allcounts._day <3)),
p8 = (SELECT AVG(p8) FROM allcounts WHERE (allcounts.count_id = SegmentAverages.count_id and allcounts._day <3)),
p9 = (SELECT AVG(p9) FROM allcounts WHERE (allcounts.count_id = SegmentAverages.count_id and allcounts._day <3)),
p10 = (SELECT AVG(p10) FROM allcounts WHERE (allcounts.count_id = SegmentAverages.count_id and allcounts._day <3))
In actuallity there are a couple hundred of these columns that begin with the letter 'p'. The divisor in the AVG computation will always be '2'. Therefore the average will always be a whole integer or a value with a .5 decimal in which case the function always rounds down. (18.5 = 18)
After this update statement is run, the 'P' columns will be summed to provide a daily total. With the AVG function always rounding down, I have the potential to loose a hundred or so in the average total. What I need is a protocol to sometimes round up and sometimes round down so that the totals remain close to where they should be. All values are integers.

Suggestions will be appreciated.
Thanks
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform