dimanche 13 mars 2016

laravel 5 query counting and grouping

Hi i need some help in my report generation

my table structure is like

flight_no  year  month ....  ...

402        2016    1
402        2016    1
403        2016    1
402        2016    2
403        2016    2
403        2016    2
403        2016    3

I want a annual report groupby months and by counting how many flight flown on each month with flight numbers. i am doing this in laravel i tried

$total_scheduled = DB::table('schedule_details')
                            ->select('id','flight_id','year','month' 
                                    DB::raw('count(id) as total_sch')
                              )
                            ->where('year','2016')
                            ->groupBy('month')
                            ->get();

it give me the total flight but i am confuse in getting all flight number for each month for eg

month 1
total_sc = 3
flight nos =402,403

month 2
total_sc = 3
flight nos =402,403

month 3
total_sc = 1
flight nos =403



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire