php - How to get Weekly data from MySQL database table using week number of month? -
i have database table studentvideos. want retrieve data table based on week number of month means how time video watched in week , time specified totaltime column in table structure , noofviews column specifies how many times video watched. week number specified column in table structure wofmonth.
lets have video named vid1, vid1 watched 2 time each 10 secs in week 1 , 1 time 10 secs in week 2.
i want response in nested array/json form in have week number tag each week , each week number video name, sum of time video watched in specific week (e.g week 1 array have vid1 time 20 secs , week 2 array have vid1 time 10 secs) , number of time video watched in week.
screenshot of studentvideos table
i tried following query don't know how modify or rewrite query desired result explained above.
"select videoid, sum(noofviews), sum(totaltime) studentvideos group videoid";
result: result of above query
after trying many different things answer simple. posting correct answer, may face such problem in future. multiple group did trick me.
query:
"select wofmonth weeknumber,videoid,sum(noofviews)as totaltime,sum(totaltime) noofviews studentvideos group wofmonth,videoid"
Comments
Post a Comment