1
I am making a select for a report of calls per carrier and each column of amount, I have a composite select that should return me the amount of calls from each carrier.
SELECT date(calldate) as 'Data',
(select count(*) FROM cdr where dstchannel like '%claro%' and (calldate between '2014-08-01' and '2014-08-11' ) ) as 'Claro',
(select count(*) FROM cdr where dstchannel like '%tim%' and (calldate between '2014-08-01' and '2014-08-11' ) ) as 'Tim',
(select count(*) FROM cdr where dstchannel like '%vivo%' and (calldate between '2014-08-01' and '2014-08-11' ) ) as 'Vivo',
(select count(*) FROM cdr where dstchannel like '%oi%' and (calldate between '2014-08-01' and '2014-08-11' ) ) as 'Oi',
(select count(*) FROM cdr where dstchannel like '%nextel%' and(calldate between '2014-08-01' and '2014-08-11' ) ) as 'Nextel'
FROM cdr where
(dstchannel regexp 'claro|Tim|vivo|oi|nextel')
and (calldate between '2014-08-01' and '2014-08-11' ) group by date(calldate)
The Result that is returned is the same value on each line with the total, without sorting by date.
You have other possible values in
dstchannel
?– bfavaretto
Yes, I do. In this case, I want to take only the 5 operators. If I take each subselect and do the separate query, it will return the correct result. But I need this to be in the same select sepadado only by column, got it?
– fabricio_wm
If each operator came on a different line, it doesn’t suit you?
– bfavaretto
Anyway, the problem is in your GROUP BY.
– bfavaretto
I think not, because each column represents an operator. If I only have the date and quantity, how will I know whose is what? I imagine it’s in group by, but I don’t know how I do it.
– fabricio_wm