PGError: ERROR: column “p.name” must appear in the GROUP BY clause or be used in an aggregate function

前端 未结 1 1912
余生分开走
余生分开走 2020-12-21 06:26

I get an error with this query. Why? I don\'t understand :(

    SELECT p.name, p.id, SUM(hours) AS hours, SUM(logged_hours) AS logged_hours
    FROM (
               


        
相关标签:
1条回答
  • 2020-12-21 07:00

    Change GROUP BY project_id to GROUP BY p.name,p.id

    The docs say:

    When GROUP BY is present, it is not valid for the SELECT list expressions to refer to ungrouped columns except within aggregate functions, since there would be more than one possible value to return for an ungrouped column.

    0 讨论(0)
提交回复
热议问题