Skip to content

[Question]: if GROUP BY alias nor aggregation function not supported, how do we support this kind of SQL? #3265

Closed

Description

@dengn

Describe your problem

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 ( number INT NOT NULL, alpha CHAR(6) NOT NULL );
INSERT INTO t1 VALUES (1413006,'idlfmv'),
(1413065,'smpsfz'),(1413127,'sljrhx'),(1413304,'qerfnd');
SELECT number, any_value(alpha), CONCAT_WS('<---->',number,any_value(alpha)) AS new
FROM t1 GROUP BY number;
SELECT CONCAT_WS('<---->',number,alpha) AS new
FROM t1 GROUP BY CONCAT_WS('<---->',number,alpha) LIMIT 1;
SELECT any_value(number), any_value(alpha), CONCAT_WS('<->',any_value(number),any_value(alpha)) AS new
FROM t1 GROUP BY new LIMIT 1;
SELECT any_value(number), any_value(alpha), CONCAT_WS('-',any_value(number),any_value(alpha),any_value(alpha),any_value(alpha),any_value(alpha),any_value(alpha),any_value(alpha),any_value(alpha)) AS new
FROM t1 GROUP BY new LIMIT 1;
SELECT any_value(number), any_value(alpha), CONCAT_WS('<------------------>',any_value(number),any_value(alpha)) AS new
FROM t1 GROUP BY new LIMIT 1;
drop table t1;

We report "column "new" does not exist" for this sql now. If we replace alias 'new' by the original CONCAT_WS..., we report 'GROUP BY clause cannot contain aggregate functions!'.

Activity

  1. added
    kind/bug
    on Jun 23, 2022
  2. added this to the v0.5.0 milestone on Jun 23, 2022
  3. removed
    kind/bug
    on Jun 23, 2022
  4. changed the title [-][Bug]: if GROUP BY alias nor aggregation function not supported, how do we support this kind of SQL?[/-] [+][Question]: if GROUP BY alias nor aggregation function not supported, how do we support this kind of SQL?[/+] on Jun 23, 2022
  5. added
    bvt
    on Jun 24, 2022
  6. fengttt commented on Jun 27, 2022

    @fengttt
    Contributor

    Both are correct behaviors and correct error messages. @daviszhen please clean tags and hand off to test.

  7. added a commit that references this issue on Jun 29, 2022
  8. added a commit that references this issue on Jun 29, 2022
  9. Ariznawlll commented on Feb 4, 2026

    @Ariznawlll
    Collaborator

    CREATE TABLE t1 (a int, b DOUBLE);
    INSERT INTO t1 VALUES (NULL, 0), (NULL, 1);
    SELECT IF(b, (SELECT a FROM t1 LIMIT 1), b) c FROM t1 GROUP BY c;
    DROP TABLE t1;

    Image

    没实现

  10. added a commit that references this issue on May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bvt

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions