Error: Invalid expression in the select list (not contained in either an aggregate function or the GROUP BY clause)

前端 未结 3 1057
花落未央
花落未央 2020-12-21 18:02

I am using Firebird SQL. The below mentioned query returns 4 rows as shown in the figure.

    SELECT a.EPS_ID,b.C_NAME,c.AY_YR_NAME,d.S_NAME,e.E_NAME
FROM 
          


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-21 18:49

    Learn to use proper, explicit JOIN syntax.

    Your problem is that all unaggregated columns need to be in the GROUP BY:

    SELECT a.EPS_ID, MAX(b.C_NAME) AS XT, c.AY_YR_NAME, d.S_NAME, e.E_NAME
    FROM TBLEXAMPLANNER_S_MSB a JOIN 
         TBLCLASS_MSB b
         ON a.EPS_CLASS_ID = b.C_ID JOIN
         TBLACADEMICYEAR_MSB c
         ON a.EPS_SESSION_ID = c.AY_ID JOIN
         TBLSUBJECTS_MSB d
         ON a.EPS_SUB_ID = d.S_ID JOIN 
         TBLEXAMTYPE_MSB e
         ON a.EPS_PE_ID = e.E_ID
    GROUP BY a.EPS_ID, c.AY_YR_NAME, d.S_NAME, e.E_NAME;
    

    Note: I would also recommend that you use table abbreviations for table aliases. So, ep for TBLEXAMPLANNER_S_MSB instead of a. Arbitrary table aliases make the query hard to follow.

提交回复
热议问题