Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
HAVING Clause in SQL
Message
 
 
To
03/07/2003 09:20:07
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00806508
Message ID:
00806510
Views:
16
This message has been marked as the solution to the initial question of the thread.
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
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform