Supposing:
- All records be duplicated.
- Duplicates always form a pair having a "Dial" and a "Hangup" in the column
lastapp
with the same uniqueid
.
- All "Hangup" elements that are filled are equal to the "Dial" elements (with the exception of
lastapp
).
So this should work:
SELECT
a.calldate AS calldate,
a.clid, AS clid,
a.src AS src,
a.dst AS dst,
a.dcontext AS dcontext,
a.channel AS channel,
a.dstchannel AS dstchannel,
'Dial + Hangup' AS lastapp,
a.lastdata AS lastdata,
(a.duration + b.duration) AS duration,
(a.billsec + b.billsec) AS billsec,
a.disposition AS disposition,
a.amaflags AS amaflags,
a.accountcode AS accountcode,
a.uniqueid AS uniqueid
FROM
tabela a
INNER JOIN
tabela b ON a.uniqueid = b.uniqueid
WHERE a.lastapp = 'Dial'
AND b.lastapp = 'Hangup'
If there are records that are not duplicated as well and you want to display them also along with the duplicate pair (which should be considered as a single record), try this:
SELECT
a.calldate AS calldate,
a.clid, AS clid,
a.src AS src,
a.dst AS dst,
a.dcontext AS dcontext,
a.channel AS channel,
a.dstchannel AS dstchannel,
IF(ISNULL(b.uniqueid), a.lastapp, 'Dial + Hangup') AS lastapp,
a.lastdata AS lastdata,
(a.duration + COALESCE(b.duration, 0)) AS duration,
(a.billsec + COALESCE(b.billsec, 0)) AS billsec,
a.disposition AS disposition,
a.amaflags AS amaflags,
a.accountcode AS accountcode,
a.uniqueid AS uniqueid
FROM
tabela a
LEFT OUTER JOIN
tabela b ON a.uniqueid = b.uniqueid
WHERE a.lastapp = 'Dial'
AND (ISNULL(b.uniqueid) OR b.lastapp = 'Hangup')
What are the table fields?
– Victor Stafusa
I didn’t understand if the two entries generated referring to the same link have equal or different ids. Could clarify this?
– Victor Stafusa
Put table fields and information more cohesively so we can help
– Theotonio
uniqueid
is notPK
and neitherUK
??– Don't Panic
not , that snep he a garbage :(
– Jasar Orion