473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Using group by date and count

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
4 4103
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bobb | last post by:
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...
3
by: Sandros | last post by:
Background: I'm collecting usability statistics for a group of applications. Each count has the following attributes: date, application, major heading, minor heading, count. My intent is to pull...
2
by: Paxton | last post by:
Hi, I'm trying to display the total page views per page within a given date range, but the correct SQL is seemingly beyond me. I get the correct result with a straightforward Group By and Count...
1
by: Job Lot | last post by:
Is it possible to use Aggregate functions with GROUP BY Clauses on DataTable. I have a DataTable with following values: Date Amount Int Balance 1/1/2004 5000.00 50.00 5050.00...
9
by: Warren | last post by:
I am trying to create a report that does the following: Access Data in Query: NAME | DATE | SALE TYPE | ------------------------- John DOE | 1282003 | TYPE A Jane DOE | 1282003 | TYPE C...
1
by: Alicia | last post by:
I basically wanted something that would do a count of the dates, then group them by their week name.. BEFORE: Resource Date Total number of times that date Appeared (Count) 4/3/03 ...
8
by: Thomas | last post by:
Hi! I´m a newbie with this and I´m trying to build a forum of my own but have stumbled on my first problem as early as the opening page. To the problem: I want to show a simple forum layout...
2
by: kirke | last post by:
Hi, I have a datetime column named dtDateTime. its format is "Oct 27 2006 12:00:00 " I want to group by only date part of it and count my code is $sql1="SELECT ...
3
by: Auddog | last post by:
I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php,...
3
by: cmartin1986 | last post by:
I have written a sql query and I need it to return 0 when it doesn't find any matches to my criteria. I have tried adding iif statements, tried sum, and just Count, all of these methods work fine to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.