全部帮助,
我在Informix中编写一个查询,并且一直停留在where子句中。我有2个CSQnames,我想要选择和某些时间以及所有其他我希望在另一个时间之间显示。我的查询完美运行,直到我添加了这个特定的where语句。如果有人可以提供建议我会非常感激。我收到一般错误。在Informix中,因为我无法在where子句中放入if then语句,我将如何重写语法?谢谢!
SELECT
(ccd.nodeid||"-"||ccd.sessionid||"-"||ccd.sessionseqnum) as sequenceID,
ccd.sessionid as sessionid,
ccd.sessionseqnum as sequencenum,
ccd.applicationName as AppName,
csqname as CSQName, ccd.flowout, ccd.conference,
CASE WHEN contacttype=1 THEN "Incoming"
WHEN contacttype=2 THEN "Outgoing"
WHEN contacttype=3 THEN "In House"
WHEN contacttype=4 THEN "Redirect In"
WHEN contacttype=5 THEN "Transfer In"
END as ContactType,
CASE WHEN contactdisposition = 1 THEN "Abandoned"
WHEN contactdisposition = 2 THEN "Handled"
WHEN contactdisposition = 4 THEN "Aborted"
WHEN contactdisposition >= 5 THEN "Rejected"
END as ContactDisposition,
CASE WHEN originatortype=1 THEN "Agent"
WHEN originatortype=2 THEN "Device"
ELSE "Unknown"
END as OriginatorType,
CASE WHEN destinationtype=1 THEN "Agent"
WHEN destinationtype=2 THEN "Device"
ELSE "Unknown"
END as DestinationType,
DATE(ccd.startdatetime) as date,
ccd.startdatetime as starttime,
ccd.enddatetime as endtime,
res.resourcename, ccd.transfer, ccd.redirect,
ccd.originatordn, ccd.destinationdn,
crd.queuetime/86400 as queuetime,
acd.talktime/86400 as TalkTime,
acd.holdtime/86400 as HoldTime,
acd.worktime/86400 as WorkTime
FROM contactcalldetail ccd
Left JOIN contactroutingdetail crd ON crd.sessionID = ccd.sessionID
AND crd.sessionSeqNum = ccd.sessionSeqNum
AND crd.nodeID = ccd.nodeID
AND crd.profileID = ccd.profileID
LEFT JOIN agentconnectiondetail acd ON acd.sessionID = ccd.sessionID
AND acd.sessionSeqNum = ccd.sessionSeqNum
AND acd.nodeID = ccd.nodeID
AND acd.profileID = ccd.profileID
LEFT JOIN resource res ON acd.resourceid = res.resourceid
left join contactqueuedetail cqd on cqd.sessionid=crd.sessionid
left join contactservicequeue csq on cqd.targetid= csq.recordid
WHERE (
ccd.startdatetime BETWEEN '2014-1-2 13:00:00' AND '2016-12-31 22:30:00'
AND (
if (csqname in ("CSQ_Emeriti" , "SOS-Emeriti")
AND EXTEND(ccd.startdatetime, HOUR TO second) > DATETIME(13:30:00) HOUR TO SECOND
AND EXTEND(ccd.startdatetime, HOUR TO second) < DATETIME(22:00:00) HOUR TO SECOND
)
or(csqname not in (“CSQ_Emeriti" , "SOS-Emeriti")
AND
EXTEND(ccd.startdatetime, HOUR TO second) > DATETIME(13:00:00) HOUR TO SECOND
AND EXTEND(ccd.startdatetime, HOUR TO second) < DATETIME(22:30:00) HOUR TO SECOND
)
)
AND WEEKDAY(ccd.startdatetime) BETWEEN 1 AND 5
AND (contacttype IN (1,4,5))
AND ccd.originatordn !='2155870700'
)
答案 0 :(得分:1)
如果查询位于 Informix ,则 SQL语句的if
子句中不提供WHERE
。
如果我理解你想要的是:
...
AND (
(
csqname in ("CSQ_Emeriti" , "SOS-Emeriti")
AND EXTEND(ccd.startdatetime, HOUR TO second) > DATETIME(13:30:00) HOUR TO SECOND
AND EXTEND(ccd.startdatetime, HOUR TO second) < DATETIME(22:00:00) HOUR TO SECOND
)
OR
(
csqname not in ("CSQ_Emeriti" , "SOS-Emeriti")
AND EXTEND(ccd.startdatetime, HOUR TO second) > DATETIME(13:00:00) HOUR TO SECOND
AND EXTEND(ccd.startdatetime, HOUR TO second) < DATETIME(22:30:00) HOUR TO SECOND
)
)
...
热切地问候。