sure…
CREATE TABLE calendar
( caldate DATE NOT NULL PRIMARY KEY
, weekday TINYINT NOT NULL
, stathol TINYINT NOT NULL
);
INSERT INTO calendar VALUES
( '2011-04-01' , 6 , 0 )
,( '2011-04-02' , 7 , 0 )
,( '2011-04-03' , 1 , 0 )
,( '2011-04-04' , 2 , 0 )
,( '2011-04-05' , 3 , 0 )
,( '2011-04-06' , 4 , 0 )
,( '2011-04-07' , 5 , 0 )
,( '2011-04-08' , 6 , 0 )
,( '2011-04-09' , 7 , 0 )
,( '2011-04-10' , 1 , 0 )
,( '2011-04-11' , 2 , 0 )
,( '2011-04-12' , 3 , 0 )
,( '2011-04-13' , 4 , 0 )
,( '2011-04-14' , 5 , 0 )
,( '2011-04-15' , 6 , 0 )
,( '2011-04-16' , 7 , 0 )
,( '2011-04-17' , 1 , 0 )
,( '2011-04-18' , 2 , 0 )
,( '2011-04-19' , 3 , 0 )
,( '2011-04-20' , 4 , 0 )
,( '2011-04-21' , 5 , 0 )
,( '2011-04-22' , 6 , 1 ) -- good friday
,( '2011-04-23' , 7 , 0 )
,( '2011-04-24' , 1 , 0 )
,( '2011-04-25' , 2 , 0 )
,( '2011-04-26' , 3 , 0 )
,( '2011-04-27' , 4 , 0 )
,( '2011-04-28' , 5 , 0 )
,( '2011-04-29' , 6 , 0 )
,( '2011-04-30' , 7 , 0 )
;
let’s have a race, shall we? you modify your fully debugged code, and i’ll modify mine…
how many fridays that aren’t a stat holiday between april 5th and april 28th?
ready… set… go…
SELECT COUNT(*)
FROM calendar
WHERE caldate BETWEEN '2011-04-05' AND '2011-04-28'
AND weekday = 6 -- fri
AND stathol = 0
answer: 2
elapsed time to develop solution: approx 12 seconds