Jump to content

SQL SELECT count by month


nashsaint

Recommended Posts

Hi,

 

Below is my sql query.

 

$query_JanCount = "SELECT count(eid) as TOTAL, a_month FROM m_month WHERE a_month = 'January'";

 

I have a table that will output the count result of the query.

 

I wanted to do same query for the other 11 months changing the WHERE clause but then i think that would be too heavy for sql to handle.  Is there a more optimized way of doing this? say, function maybe?  or an array? I don't have any idea how to code it. 

 

Any help is greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/151614-sql-select-count-by-month/
Share on other sites

thanks a lot for your help. it worked but i have another problem. sorry if i didn't mention it beforehand.

 

This is how i'm hoping the result would look like:

Firstname

january

february

result -->

Mark

121

234

result -->

Anthony

4324

234

 

and if i group it by month it produced a different result.  I tried grouping it in Firstname but now the count result counts everything from the database and doesn't separate by month.

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.