473,653 Members | 2,968 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 4125
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_MO NTH 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**********@y ahoo.com> wrote in message
news:up******** *****@read3.ine t.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_MO NTH 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**********@y ahoo.com> wrote in message
news:up******** *****@read3.ine t.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_MO NTH 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**********@y ahoo.com> wrote in message
news:up******** *****@read3.ine t.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_MO NTH 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 select field,count(*) from table where datefield > 2004/2/1 and datefield < 2004/2/29
3
2469
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 this back as XML and render it in to an HTML table. I have all this working and all the files are below. I would value any feedback. A simple example of the data looks like this:
2
3087
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 clause eg SELECT DISTINCT tblPageViews.PageVisited, Count(tblPageViews.PageVisited) AS CountOfPageVisited FROM tblPageViews GROUP BY tblPageViews.PageVisited;
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 1/1/2004 4000.00 40.00 4040.00 1/2/2004 1000.00 10.00 1010.00 1/2/2204 2000.00 20.00 2020.00 1/3/2004 1500.00 15.00 1515.00 I want my resultant DataTable to show in DataGrid as
9
1604
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 Jane DOE | 1282003 | TYPE D Jane DOE | 1282003 | TYPE C
1
2139
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 4 4/4/03 2 (note 4/4/03 showed up twice) 4/9/03 1
8
4724
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 with tables looking something like this Forum Name | Topics | Posts | Last Post
2
11996
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 convert(varchar,J1708Data.dtDateTime,120), count(convert(varchar,J1708Data.dtDateTime,120))
3
3105
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, I use: $query2 = "SELECT id, order_no, price, count(item_no) as count from production where item_no = '27714";
3
10010
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 return the values when it finds matches, but i need it also to return a 0 when there are no matches. Here is what I got. SELECT "CAL Recieved" as Tags, .,sum(iif(.,1,0)) AS FROM GROUP BY . HAVING (((.)=(Date()-1))); UNION ALL SELECT...
0
8283
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8704
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8470
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5620
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2707
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 we have to send another system
2
1591
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.