That's not a general rule for preferring bags to sets, it's an exception to the rule.
In any event, I think it's also a mistake. You want two aggregate functions, SUM and COUNT. If you're iterating over duplicate results like that, you've made a mistake. Ignoring that most (all?) SQL implementations support an AVG operator, you could always do this:
SELECT SUM(age) / COUNT(age) AS average_age FROM tableSo with all due respect, even your special case doesn't seem to me to be applicable.
Of course, that's brings up a related issue:
SELECT SUM(customer_id) / COUNT(customer_id) FROM customersThat's clearly nonsense but it's quite legal. If SQL followed the relational model it wouldn't even compile.
Cheers,
Ovid
New address of my CGI Course.
In reply to Re^6: (OT) Why SQL Sucks (with a little Perl to fix it)
by Ovid
in thread (OT) Why SQL Sucks (with a little Perl to fix it)
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |