I am trying to see 2 conditional columns using the WHERE
clause from 1 column.
For example:
I have a dataset where I have a long list of calls. I would like to see two different columns where the first column shows a count of all those calls who are equal or longer that 0 seconds and a second column that shows a count of all those calls that are equal or longer to 120 seconds.
That is my first query:
SELECT distinct year(date) Year, monthname(date) as Month, count(calls) Leads
FROM database.calls
where duration >= 120
and year(date) = 2022
group by month(date)
order by max(date);
second query: (The only difference it's on the 3rd line where duration is equal to 0)
SELECT distinct year(date) Year, monthname(date) as Month, count(calls) Leads
FROM database.calls
where duration >= 0
and year(date) = 2022
group by month(date)
order by max(date);
Expected Result:
Year | Month | Calls(0sec) | Calls(120sec) |
---|---|---|---|
2022 | January | 654 | 521 |
2022 | February | 895 | 465 |
2022 | March | 562 | 321 |