469,331 Members | 1,782 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,331 developers. It's quick & easy.

Query Formating In Sql-need help

Hi can one help me in sorting out the query
This is the table I have with me.
Can one help me in sorting out the query.


start_date end_date bus_hol
2007-04-14 2007-05-01 ?
2007-04-03 2007-05-01 2007-11-01
2007-04-18 2007-05-01 2007-11-09
2007-04-01 2007-05-01 2007-09-19
2007-04-02 2007-05-01 2007-09-02
2007-03-29 2007-05-01 2007-08-15
2007-04-04 2007-05-01 2007-11-08
2007-04-07 2007-05-01 2007-12-21
2007-04-17 2007-05-01 ?
2007-04-09 2007-05-01 ?
2007-03-31 2007-05-01 2007-01-26
2007-04-15 2007-05-01 ?
2007-04-10 2007-05-01 ?
2007-04-13 2007-05-01 2007-12-24
2007-04-05 2007-05-01 ?
2007-03-28 2007-05-01 2007-04-06
2007-04-11 2007-05-01 ?
2007-04-12 2007-05-01 ?
2007-03-30 2007-05-01 2007-01-01
2007-04-08 2007-05-01 2007-12-25
2007-04-06 2007-05-01 ?
2007-04-16 2007-05-01 2007-12-31



The output should be as follows.
The bus_hol should be between start_date and end_date

Start_date end_date count(bus_hol)
2007-04-14 2007-05-01 0
.
.
.

.
.

.
2007-04-05 2007-05-01 1 (bec 2007-04-06 is betwwen start_ date and end_date)

Thanks in Advance

krishna
May 2 '07 #1
3 1011
MMcCarthy
14,534 Expert Mod 8TB
Try this, not sure if it will work
Expand|Select|Wrap|Line Numbers
  1. SELECT  start_date, end_date, 
  2. Sum(IF bus_hol BETWEEN  start_date AND end_date 1 ELSE 0) As CountBusHol
  3. FROM tablename
  4. GROUP BY start_date, end_date
  5.  
May 2 '07 #2
Try this, not sure if it will work
Expand|Select|Wrap|Line Numbers
  1. SELECT  start_date, end_date, 
  2. Sum(IF bus_hol BETWEEN  start_date AND end_date 1 ELSE 0) As CountBusHol
  3. FROM tablename
  4. GROUP BY start_date, end_date
  5.  
Hi Thank you.
i tried its giving some different results than my expectations.
May 3 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Hi Thank you.
i tried its giving some different results than my expectations.
Look at each date range and see if you can follow what results are being produced and how this differs from expeced results.
May 3 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by jaysonsch | last post: by
reply views Thread by rodrigo guerra | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.