Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-7029

AVG() without group by on non matching row returns NULL

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Not a Bug
    • None
    • N/A
    • Optimizer
    • None

    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

      Attachments

        Activity

          People

            serg Sergei Golubchik
            jocel1 jocelyn fournier
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.