Question

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?

Was it helpful?

Solution

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).

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top