By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 1,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

Using group by date and count

P: n/a
Is there a way to select count(*) by grouping by date, and having multiple
date ranges?

combining...

select field,count(*) from table where datefield > 2004/1/1 and datefield <
2004/1/31
and
select field,count(*) from table where datefield > 2004/2/1 and datefield <
2004/2/29
so that the output is

field 34
field 40
tia

bobb

Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
bobb wrote:
Is there a way to select count(*) by grouping by date, and having multiple
date ranges?


Do you mean random date ranges (if yes, then how many ranges are we
talking about, and is the amount of ranges always the same?)

Or do you mean you want to group for example by year and month? If yes,
this might be a little easier because you can extract year and month
from date and then do "group by year, month" or "group by year_month"

Example:
mysql> SELECT EXTRACT(YEAR_MONTH FROM '1999-07-02 01:02:03');
-> 199907

More date and time functions:
http://www.mysql.com/doc/en/Date_and...functions.html
Jul 19 '05 #2

P: n/a
thanks Aggro,
I'm grouping the results by month... thanks for the pointer.
bobb

"Aggro" <sp**********@yahoo.com> wrote in message
news:up*************@read3.inet.fi...
bobb wrote:
Is there a way to select count(*) by grouping by date, and having multiple date ranges?


Do you mean random date ranges (if yes, then how many ranges are we
talking about, and is the amount of ranges always the same?)

Or do you mean you want to group for example by year and month? If yes,
this might be a little easier because you can extract year and month
from date and then do "group by year, month" or "group by year_month"

Example:
mysql> SELECT EXTRACT(YEAR_MONTH FROM '1999-07-02 01:02:03');
-> 199907

More date and time functions:
http://www.mysql.com/doc/en/Date_and...functions.html

Jul 19 '05 #3

P: n/a
thanks Aggro,
I'm grouping the results by month... thanks for the pointer.
bobb

"Aggro" <sp**********@yahoo.com> wrote in message
news:up*************@read3.inet.fi...
bobb wrote:
Is there a way to select count(*) by grouping by date, and having multiple date ranges?


Do you mean random date ranges (if yes, then how many ranges are we
talking about, and is the amount of ranges always the same?)

Or do you mean you want to group for example by year and month? If yes,
this might be a little easier because you can extract year and month
from date and then do "group by year, month" or "group by year_month"

Example:
mysql> SELECT EXTRACT(YEAR_MONTH FROM '1999-07-02 01:02:03');
-> 199907

More date and time functions:
http://www.mysql.com/doc/en/Date_and...functions.html

Jul 19 '05 #4

P: n/a
thanks Aggro,
I'm grouping the results by month... thanks for the pointer.
bobb

"Aggro" <sp**********@yahoo.com> wrote in message
news:up*************@read3.inet.fi...
bobb wrote:
Is there a way to select count(*) by grouping by date, and having multiple date ranges?


Do you mean random date ranges (if yes, then how many ranges are we
talking about, and is the amount of ranges always the same?)

Or do you mean you want to group for example by year and month? If yes,
this might be a little easier because you can extract year and month
from date and then do "group by year, month" or "group by year_month"

Example:
mysql> SELECT EXTRACT(YEAR_MONTH FROM '1999-07-02 01:02:03');
-> 199907

More date and time functions:
http://www.mysql.com/doc/en/Date_and...functions.html

Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.