zlacker

[parent] [thread] 5 comments
1. 0cf861+(OP)[view] [source] 2024-08-24 16:50:46
Indeed. Just as I think git’s N different ways to refer to the same operation was a blunder.
replies(1): >>andy80+J
2. andy80+J[view] [source] 2024-08-24 16:57:29
>>0cf861+(OP)
But pre- and post- aggregation filtering is not really "the same" operation.
replies(1): >>0cf861+61
◧◩
3. 0cf861+61[view] [source] [discussion] 2024-08-24 17:01:29
>>andy80+J
If I use a CTE and filter the aggregate, feels the same to me.
replies(1): >>andy80+db
◧◩◪
4. andy80+db[view] [source] [discussion] 2024-08-24 18:20:20
>>0cf861+61
If you perform an aggregation query in a CTE, then filter on that in a subsequent query, that is different, because you have also added another SELECT and FROM. You would use WHERE in that case whether using a CTE or just an outer query on an inner subquery. HAVING is different from WHERE because it filters after the aggregation, without requiring a separate query with an extra SELECT.
replies(1): >>RaftPe+Ux
◧◩◪◨
5. RaftPe+Ux[view] [source] [discussion] 2024-08-24 21:21:58
>>andy80+db
> HAVING is different from WHERE because it filters after the aggregation, without requiring a separate query with an extra SELECT.

Personally I rarely use HAVING and instead use WHERE with subqueries for the following reasons:

1-I don't like repeating/duplicating a bunch of complex calcs, easier to just do WHERE in outer query on result

2-I typically have outer queries anyway for multiple reasons: break logic into reasonable chunks for humans, also for join+performance reasons (to give the optimizer a better chance at not getting confused)

replies(1): >>sgarla+122
◧◩◪◨⬒
6. sgarla+122[view] [source] [discussion] 2024-08-25 13:54:17
>>RaftPe+Ux
The main (only?) task I routinely use HAVING for is finding duplicates.
[go to top]