Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Different behavior of COUNT(*) and SUM()
Message
 
 
À
04/11/2008 21:28:53
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01359217
Message ID:
01359693
Vues:
25
May be I didn't check help thoroughly enough. I found this interesting discussion
Re: Something out of nothing - the aggregate. Thread #1128076

>>I don't think this behavior is properly documented in Help. All I can find is
>>-------------------------------------------------------------------------------------------------------------
>>When you use aggregate functions, such as MAX( ), in the SQL SELECT command without a GROUP BY clause, and the system does not find any matching records, Visual FoxPro returns a result set with a single record and it sets _TALLY to 1. In versions before Visual FoxPro 9.0, the system does not return any records and it sets _TALLY to 0.
>>--------------------------------------------------------------------------------------------
>>
>>It doesn't tell you that COUNT may return a number and the SUM would return NULL. So, I guess, you can find this by trial and error method.
>
>Basically, yes. But it makes sense - count(*) will return the count of _any_ records, therefore no nulls because it is counting real records, and "no records found" returns a real zero, not a null, because it can't say "I don't know whether I found any records".
>
>SUM(), however, has to account for the case when all the fields it sums contain null - in which case, the total will be equally absent, i.e. sum of no-not-null numbers is a null (how's "no-not-null" for a triple negation, eh?).
>
>OK, one more try: if sum(xField) is sum of all nulls, what else can it be but null? Can't invent numbers when there aren't any.

So, we have to be careful using aggregate functions without GROUP BY.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform