문제

I have a problem with Informix SQL syntax.

This is my SQL syntax

sql = "SELECT MONTH(startdatetime) MONTH, COUNT(sessionid) TotalCallsOffered, "+

      " CASE" +
      " WHEN MONTH(startdatetime) = 5" +
      " THEN 'SUSUKUDA' " +
      " END " +

      "FROM agentconnectiondetail a WHERE MONTH(startdatetime) = 5 " +
      "GROUP BY 1 ORDER BY 1 ASC";

and the output is

ERROR [HY000] [Informix][Informix ODBC Driver][Informix] The column ((expression))
must be in the GROUP BY list.

What must I do?

도움이 되었습니까?

해결책

Informix follows the strict SQL standard and requires all non-aggregate values in the select list to be listed in the GROUP BY clause. Thus, the SQL must look like:

SELECT MONTH(startdatetime) AS Month, COUNT(sessionid) AS TotalCallsOffered,
       CASE
       WHEN MONTH(startdatetime) = 5
       THEN 'SUSUKUDA'
       END AS Susukuda
  FROM agentconnectiondetail
 WHERE MONTH(startdatetime) = 5
 GROUP BY Month, Susukuda
 ORDER BY Month ASC

I've chosen to name all three columns with AS and to GROUP BY those names (and ORDER BY them too).

다른 팁

My problem solved with this

SELECT MONTH(startdatetime) AS Month, COUNT(sessionid) AS TotalCallsOffered,
       CASE
       WHEN MONTH(startdatetime) = 5
       THEN 'SUSUKUDA'
       END AS Susukuda
  FROM agentconnectiondetail
 WHERE MONTH(startdatetime) = 5
 GROUP BY 1, 3
 ORDER BY 1
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top