我遇到Informix SQL语法问题。
这是我的SQL语法
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";
,输出
ERROR [HY000] [Informix][Informix ODBC Driver][Informix] The column ((expression))
must be in the GROUP BY list.
我该怎么办?
答案 0 :(得分:4)
Informix遵循严格的SQL标准,并要求选择列表中的所有非聚合值都列在GROUP BY子句中。因此,SQL必须如下所示:
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
我选择使用AS命名所有三列,并选择GROUP BY这些名称(以及ORDER BY)。
答案 1 :(得分:0)
我的问题解决了这个
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