Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
HAVING Clause in SQL
Message
De
03/07/2003 09:32:15
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00806508
Message ID:
00806512
Vues:
15
Hey Sergey,

How did I know it would be you to respond? <s>

So, it almost like the SQL runs with the GROUP BY and then another WHERE is put on the results with the HAVING clause?

What is the HAVING clause normally used for? To filter records after the SQL has processed?

Renoir

>Hi Renoir,
>
>The HAVING clause is applied after grouping is done. In your case it only includes records that have the same values in xxxZERO and xxxOther group of fields.
>
>>Can anyone help me understand what the HAVING clause is doing in this statement?
>>
>>Thanks! Renoir
>>
>>
>>SELECT a.*,;
>>	SUM(IIF(b.acct_id = 0, 1, 0)) cntZERO,;
>>	SUM(IIF(b.acct_id = 0, b.econ, 0.00)) econZERO,;
>>	SUM(IIF(b.acct_id = 0, b.emat, 0.00)) ematZERO,;
>>	SUM(IIF(b.acct_id = 0, b.nProfits, 0.00)) PSZERO,;
>>	SUM(IIF(b.acct_id <> 0, 1, 0)) cntOTHER,;
>>	SUM(IIF(b.acct_id <> 0, b.econ, 0.00)) econOTHER,;
>>	SUM(IIF(b.acct_id <> 0, b.emat, 0.00)) ematOTHER,;
>>	SUM(IIF(b.acct_id <> 0, b.nProfits, 0.00)) PSOTHER;
>>	FROM temp1 AS a, acctcont AS b;
>>	WHERE a.invnum = b.invnum AND a.contrib_dt = b.contrib_dt AND b.transtype = 'T';
>>	GROUP BY a.invnum, a.contrib_dt;
>>	HAVING ;
>>		ABS(econZERO) = ABS(econOTHER) AND ;
>>		ABS(ematZERO) = ABS(ematOTHER) AND ;
>>		ABS(PSZERO) = ABS(PSOTHER) ;
>>		AND cntZERO = cntOTHER;
>>	INTO TABLE temp
>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform