Re: Query Help?
Posted in 1995
Frank93ZX6 (frank93zx6@aol.com) wrote:
: I can't seem to find a general SQL newsgroup, so can someone here help?
: I have a table with the following information
: ID #
: at_date
: am_code
: pm_code
: I need to find all ID #'s that have a value (ie is not NULL) for the am
: and pm codes for EVERY day from 06/12/95 to 06/15/95. So the ID # must
: have not null values for ALL 5 days. Using informix for AIX (RS/6000) 4.1
: Thanks, Frank
SELECT id FROM table
WHERE NOT am IS NULL and NOT pm IS NULL AND
at_date BETWEEN "6/12/95" AND "6/15/95"
GROUP BY 1
HAVING COUNT(*) = DATE("6/15/95") - DATE("6/12/95") + 1
It works, if (id, at_date) is a key of your table. If not, you can use:
SELECT id, date from table
WHERE at_date BETWEEN "6/12/95" AND "6/15/95"
GROUP BY 1, 2
HAVING COUNT(*) = DATE("6/15/95") - DATE("6/12/95") + 1 AND
NOT MIN(am_code || pm_code) IS NULL
WBR, Vadim J. Nikitin