2012-06-29 67 views
1

如何在Informix中使用group by子句?Informix小時分組

由部分集團在這裏給出了一個錯誤:

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; 

回答

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 
+0

它不會出現,雖然你可以ORDER BY表達式甚至顯示標籤(選擇列表中的列別名),您無法對GROUP BY執行相同的操作。 –