Query Question: How to select all days within a period

This is a discussion on Query Question: How to select all days within a period within the MySQL Database forums, part of the Database Forums category; Hi all, I have what I think is a rather a curly question: Is there a way to select all ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-05-2008
supagroova
 
Posts: n/a
Default Query Question: How to select all days within a period

Hi all,

I have what I think is a rather a curly question:

Is there a way to select all days in a month (or week, year, any
period) without having matching rows in a table?

So in essence, can I create a query that returns all the days in a
period without looking up a table?

To give some background, I am trying to output records for a graphing/
reporting tool and I only have non-zero records in my table.

Any insights, suggestions are warmly welcomed!

Thanks.
Reply With Quote
  #2 (permalink)  
Old 05-05-2008
ZeldorBlat
 
Posts: n/a
Default Re: Query Question: How to select all days within a period

On May 5, 8:37 am, supagroova <supagro...@gmail.com> wrote:
> Hi all,
>
> I have what I think is a rather a curly question:
>
> Is there a way to select all days in a month (or week, year, any
> period) without having matching rows in a table?
>
> So in essence, can I create a query that returns all the days in a
> period without looking up a table?
>
> To give some background, I am trying to output records for a graphing/
> reporting tool and I only have non-zero records in my table.
>
> Any insights, suggestions are warmly welcomed!
>
> Thanks.


Not that I know of other than creating a temporary table then filling
it with values. It isn't uncommon to have a "calendar" table that
just includes every date within some reasonable range. You'd be
surprised at how much easier that makes some things -- then it's just
an outer join from that table and you have all your zeros.
Reply With Quote
  #3 (permalink)  
Old 05-05-2008
cvh@LE
 
Posts: n/a
Default Re: Query Question: How to select all days within a period

On May 5, 3:00*pm, ZeldorBlat <zeldorb...@gmail.com> wrote:
> On May 5, 8:37 am, supagroova <supagro...@gmail.com> wrote:
>
>
>
> > Hi all,

>
> > I have what I think is a rather a curly question:

>
> > Is there a way to select all days in a month (or week, year, any
> > period) without having matching rows in a table?

>
> > So in essence, can I create a query that returns all the days in a
> > period without looking up a table?

>
> > To give some background, I am trying to output records for a graphing/
> > reporting tool and I only have non-zero records in my table.

>
> > Any insights, suggestions are warmly welcomed!

>
> > Thanks.

>
> Not that I know of other than creating a temporary table then filling
> it with values. *It isn't uncommon to have a "calendar" table that
> just includes every date within some reasonable range. *You'd be
> surprised at how much easier that makes some things -- then it's just
> an outer join from that table and you have all your zeros.


I absolutely agree with Zaldor. I usually have a `sequence` table
running from 1..366 for all days in a year. Very helpful indeed

Reply With Quote
  #4 (permalink)  
Old 05-06-2008
supagroova
 
Posts: n/a
Default Re: Query Question: How to select all days within a period

Thanks guys. That's a big help!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:44 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0