我有一个包含以下条目的MySQL会话表
if(comboBox.SelectedItem.ToString() == "90")
我希望sessionid conversationid agentid Reason
s1 c1 a1 r1
s2 c1 a1 r2
s3 c2 a2 r1
s4 c3 a3 r2
用于sesionid
和agentid
相同且首次出现原因为conversationid
的行。
预期输出:
r1
答案 0 :(得分:0)
select
b.sessionid,
b.conversationid,
b.agentid,
b.closeReason,
b.assignTs
from
(select
*
from
session
where
substr(assignTs,1,10) = '2018-07-11'
) as b
inner join
(select
conversationid,
agentid,
count(*) c,
sessionid,
closeReason
from
session
where
substr(assignTs,1,10) = '2018-07-11'
and
conversationid in
(select
conversationid
from
session
where
closeReason = 'PENDING_CUST_UPDATE'
and
substr(assignTs,1,10) = '2018-07-11')
group by
conversationid, agentid having c > 1
) as a
on
a.agentid = b.agentid
and
a.conversationid =b.conversationid
and
a.closeReason = 'PENDING_CUST_UPDATE'
order by
b.agentid,
b.conversationid