Details
Description
Hi,
I wonder if it's a bug or a feature, but I find this behaviour quite disturbing.
If there's no join and if AVG() is used without GROUP BY and with a WHERE clause on a non matching row, it still returns a result.
e.g. :
MariaDB [(none)]> SELECT AVG(a), b FROM (SELECT 1 as a, 1 as b) a WHERE b=10; +--------+---+ | AVG(a) | b | +--------+---+ | NULL | NULL | +--------+---+
However, if a GROUP BY is added, no rows are returned :
SELECT AVG(a), b FROM (SELECT 1 as a, 1 as b) a WHERE b=10 GROUP BY a;
Empty set (0.00 sec)
Thanks and regards,
Jocelyn Fournier
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Quoting the standard (ISO/IEC 9075-2:2003, 4.15 Data analysis operations):
That explains that NULL is correct. Even more:
But if you add GROUP BY you should get one row per group, as there are no groups you get no rows.