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