Subject | Re: [firebird-support] SELECT MIN |
---|---|
Author | Alejandro Garcia |
Post date | 2007-04-24T09:12:33Z |
Hi, I have this problem: my table is
PATIENTID, DATE, DIFF
for each PATIENTID can be many DATE and many DIFF, DIFF is an integer and I need for each PATIENTID the MIN DIFF and the DATE of the same line where MIN(DIFF) is.
I did this: but it's not working
SELECT PATIENTID,DATE,DIFF FROM T MYTABLE
WHERE DIFF = (SELECT MIN(DIFF) FROM Q MYTABLE
WHERE (T.PATIENTID = Q.PATIENTID
AND T.DATE = Q.DATE )
Tetram Corp <dev@...> escribió:
if you need the Date2 of the same line where Min(Date1) is, you can do
something like that:
select clientid, date1, date2 from mytable t1
where date1 = (select min(date1) from mytable t2 where t1.clientid =
t2.clientid)
fAlejandro Garcia a écrit :
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
[Non-text portions of this message have been removed]
PATIENTID, DATE, DIFF
for each PATIENTID can be many DATE and many DIFF, DIFF is an integer and I need for each PATIENTID the MIN DIFF and the DATE of the same line where MIN(DIFF) is.
I did this: but it's not working
SELECT PATIENTID,DATE,DIFF FROM T MYTABLE
WHERE DIFF = (SELECT MIN(DIFF) FROM Q MYTABLE
WHERE (T.PATIENTID = Q.PATIENTID
AND T.DATE = Q.DATE )
Tetram Corp <dev@...> escribió:
if you need the Date2 of the same line where Min(Date1) is, you can do
something like that:
select clientid, date1, date2 from mytable t1
where date1 = (select min(date1) from mytable t2 where t1.clientid =
t2.clientid)
fAlejandro Garcia a écrit :
> Hi! I have a 3 columns table: CLIENTID DATE1 DATE2---------------------------------
> for each CLIENTID can be more than one DATE1 so I have to select the MIN. Just doing this works fine:
> SELECT MIN (DATE1)
> from mytable
> group by CLIENTID
> Now I need also to show DATE2 in the result, if I include it in the SELECT I need to include it in the GROUP BY but if I do that I don't get the MIN(DATE1)for each CLIENTID: it returns all of them..
>
>
>
>
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
[Non-text portions of this message have been removed]