1

如何在 Informix 中将 group by 子句与小时一起使用?

这里的 group by section 给出了一个错误:

  SELECT
     cqdr.targetid, 
     cqdr.profileid, 
     ccdr.startdatetime::DATETIME HOUR TO HOUR AS CallHour,
     Count(cqdr.sessionid), 
     (Sum(cqdr.queuetime) / Count(cqdr.sessionid)), 
     Max(cqdr.queuetime)
   FROM Contactqueuedetail cqdr, Contactcalldetail ccdr, Selected_csqs sc
   WHERE cqdr.sessionid = ccdr.sessionid AND
         cqdr.sessionseqnum = ccdr.sessionseqnum AND
         cqdr.profileid = ccdr.profileid AND
         cqdr.nodeid = ccdr.nodeid AND
         ccdr.startdatetime BETWEEN DATE('12/6/27') AND DATE('12/6/28') AND 
         --cqdr.targettype = l_typecsq AND
         cqdr.targetid = sc.csqrecordid AND
         cqdr.profileid = sc.profileid
   GROUP BY ccdr.startdatetime::DATETIME HOUR TO HOUR, cqdr.targetid, cqdr.profileid;
4

1 回答 1

2

要按派生列分组,请使用 GROUP BY 序号位置语法:

SELECT cqdr.targetid, 
     cqdr.profileid, 
     ccdr.startdatetime::DATETIME HOUR TO HOUR AS CallHour,
     Count(cqdr.sessionid), 
     (Sum(cqdr.queuetime) / Count(cqdr.sessionid)), 
     Max(cqdr.queuetime)
  FROM ...
  WHERE ...
GROUP BY 1, 2, 3
于 2012-06-30T07:48:06.257 回答