Jump to content

group by quarter in multiple years


amolv

Recommended Posts

$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

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.