(select 'JAN'as month, t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-1-1'
and trip_date <= date '2020-1-31'
group by t.vehicle_ownerid)
union all
(select 'FEB'as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-2-1'
and trip_date <= date '2020-2-29'
group by t.vehicle_ownerid)
union all
(select 'MAR' as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-3-1'
and trip_date <= date '2020-3-31'
group by t.vehicle_ownerid)
union all
(select 'APR' as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-4-1'
and trip_date <= date '2020-4-30'
group by t.vehicle_ownerid)
union all
(select 'MAY' as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-5-1'
and trip_date <= date '2020-5-31'
group by t.vehicle_ownerid)
union all
(select 'JUN' as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-6-1'
and trip_date <= date '2020-6-30'
group by t.vehicle_ownerid)
union all
(select 'JUL' as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-7-1'
and trip_date <= date '2020-7-31'
group by t.vehicle_ownerid)
union all
(select 'AUG' as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-8-1'
and trip_date <= date '2020-8-31'
group by t.vehicle_ownerid)
union all
(select 'SEP' as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-9-1'
and trip_date <= date '2020-9-30'
group by t.vehicle_ownerid)
union all
(select 'OCT' as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-10-1'
and trip_date <= date '2020-10-31'
group by t.vehicle_ownerid)
union all
(select 'NOV' as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-11-1'
and trip_date <= date '2020-11-30'
group by t.vehicle_ownerid)
union all
(select 'DEC' as month,t.vehicle_ownerid,(sum(t.total_payment))as total_income from trips t,vehicles v ,vehicle_owner vo
where
v.VEHICLE_ID =t.VEHICLE_ID`enter code here`
and vo.vehicle_ownerid =v.vehicle_ownerid and trip_date >= date '2020-12-1'
and trip_date <= date '2020-12-30'
group by t.vehicle_ownerid);