>
> And so I tried this here:
>
> SELECT tr_id, tr_date FROM crtrd1
> WHERE tr_unit = 'SMA' AND (tr_type = 'A' OR tr_type = 'I')
> AND tr_date > tr_date IN
> (SELECT tr_date FROM crtrd1
> WHERE tr_unit = 'SMA' AND (tr_type = 'T' OR tr_type = 'O'))
> ORDER BY tr_date DESC;
>
How about
CREATE FUNCTION F(int,char) returns int4 as
'SELECT max(tr_date) FROM crtd1
WHERE $1=tr_id
AND $2=tr_unit
AND (tr_type = \'A\' OR
tr_type = \'I\');'
language 'sql';
and then search as:
SELECT distinct tr_id,F(tr_id) from crtd1;