amolv Posted May 20, 2011 Share Posted May 20, 2011 $sq ="SELECT count(id),QUARTER(Date(last_call)) as quarter,YEAR(last_call) FROM $dbt.travel_crm WHERE Date(last_call) BETWEEN '".$_GET['startdate']."' AND '".$_GET['enddate']."' GROUP BY QUARTER(Date(last_call)) ORDER BY YEAR(last_call)"; giving only current years rows count, bcoz grouping by quarter, i need to group by (quarter,year) , how to do that? example id last_call 1 2010-10-30 10:56:00 2 2010-10-30 10:56:00 3 2011-01-30 10:56:00 4 2011-02-30 10:56:00 5 2011-03-30 10:56:00 6 2011-05-30 10:56:00 7 2011-04-30 10:56:00 8 2011-04-30 10:56:00 9 2011-05-30 10:56:00 10 2011-04-30 10:56:00 what to order by or how to order before group by? Link to comment https://forums.phpfreaks.com/topic/236946-group-by-quarter-in-multiple-years/ Share on other sites More sharing options...
amolv Posted May 20, 2011 Author Share Posted May 20, 2011 $sq ="SELECT count(id),QUARTER(Date(last_call)) as quarter,YEAR(last_call) FROM $dbt.travel_crm WHERE Date(last_call) BETWEEN '".$_GET['startdate']."' AND '".$_GET['enddate']."' GROUP BY QUARTER(Date(last_call)) ORDER BY YEAR(last_call)"; giving only current years rows count, bcoz grouping by quarter, i need to group by (quarter,year) , how to do that? example id last_call 1 2010-10-30 10:56:00 2 2010-10-30 10:56:00 3 2011-01-30 10:56:00 4 2011-02-30 10:56:00 5 2011-03-30 10:56:00 6 2011-05-30 10:56:00 7 2011-04-30 10:56:00 8 2011-04-30 10:56:00 9 2011-05-30 10:56:00 10 2011-04-30 10:56:00 what to order by or how to order before group by? very simple group by year,quarter Thank you all. Link to comment https://forums.phpfreaks.com/topic/236946-group-by-quarter-in-multiple-years/#findComment-1217951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.