Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause

后端 未结 2 1058
温柔的废话
温柔的废话 2021-01-12 06:57

In the below sql statement i get the following error

Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP B

2条回答
  •  渐次进展
    2021-01-12 07:43

    You do not need to group by that CASE expression.

    SELECT
        T.Post,
        COUNT(*) AS ClientCount,
        CASE COUNT(*) WHEN '1' THEN MIN(T.Client) ELSE '[Clients]' END Client
    FROM
        MyTable T
    GROUP BY
        T.Post
    

提交回复
热议问题