I need to select data from the table that looks somewhere about this:
monthStart monthEnd newPhones totalPhones oblid
1 1 1 2 1
2 2 1 2 2
1 2 2 2 3
2 2 1 1 4
2 3 0 3 5
So I want to select 4 fields: month, count obj for months on the base of monthStart, sum of newPhones on the base of monthEnd, sum of totalPhones on the base of monthEnd.
So for this data I need to select this:
month count totalPhones newPhones
1 3 2 1
2 2 5 4
3 0 3 0
count for 1st month = 3 as we have 3 rows with monthStart = 1, but we have only one row with monthEnd = 1, so totalPhones for 1 month = 2, newPhones = 1 count for 3d month = 0 as we have 0 rows with monthStart = 3, but we have 3 totalPhones and 0 newPhones for monthEnd = 3 - we should show this data.
I've stuck with this. I've tried to select from the result of this select:
SELECT
monthStart,
monthEnd,
count(1) as uploaded,
sum(newPhones) as newPhones,
sum(totalPhones) as totalPhones
from TestGB
group by monthEnd, monthStart
but I can't get ideal result. Thank you for your help!