Connecting Tech Pros Worldwide Forums | Help | Site Map

most recent, min/max query

getyourbiglobster
Guest
 
Posts: n/a
#1: Nov 13 '05
hello-

i have a sample database that i want to query for most recent SAMPLE,
min SAMPLE_RESULT, and max SAMPLE_RESULT.

the table is orgainzed as such:
SAMPLE | SAMPLE_DATE | SAMPLE_TIME | SAMPLE_RESULT

any ideas?


MGFoster
Guest
 
Posts: n/a
#2: Nov 13 '05

re: most recent, min/max query


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If possible, you should put the sample_date & time in one column, it
will eliminate the need to create an expression in the WHERE clause that
creates a DateTime data type. Since you don't give a DDL definition of
your table I'll have to guess at the data types. I'll assume that your
sample_date & time are stored as DateTime data types. If they aren't
DateTimes you have to convert them using the CDate() function before
adding them together. Note that #3:30# is 3:30 AM (0330) and #03:30PM#
is 3:30 PM (1530).

Just a guess:

SELECT sample, Min(sample_result) As min_result, Max(sample_result) as
max_result
FROM table_name as t
WHERE sample_date + sample_time =
(SELECT Min(sample_date + sample_time)
FROM table_name
WHERE sample = t.sample)

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQgzzYIechKqOuFEgEQJV7gCg1hDXXhtf7JQvZoI315JRPo E3Vw0AoJU3
1r2ZLlYyylNhERy9aWh3YSsN
=W7eX
-----END PGP SIGNATURE-----


getyourbiglobster wrote:[color=blue]
> hello-
>
> i have a sample database that i want to query for most recent SAMPLE,
> min SAMPLE_RESULT, and max SAMPLE_RESULT.
>
> the table is orgainzed as such:
> SAMPLE | SAMPLE_DATE | SAMPLE_TIME | SAMPLE_RESULT[/color]
Closed Thread