473,503 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4107
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
776
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
2450
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
3082
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
1387
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
1593
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
2119
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
4720
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
11983
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
3086
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
10004
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
7205
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
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
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
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.