Informix按小时分组

时间:2012-06-29 21:06:59

标签: datetime informix hour

如何在Informix中使用带有小时的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 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;

1 个答案:

答案 0 :(得分: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