|
|
Archives of the TeradataForum
Message Posted: Wed, 30 Apr 2008 @ 17:49:06 GMT
Subj: | | Re: Retrieving the Second Highest Amount |
|
From: | | Sonje, Zdravko |
Megan, you can run two statements and then use union to get desired records.
with this you get second highest record:
select max(amount), customer from table where (amount, customer) not in
(select max(amount), customer from table group by customer) and date =
some_date group by customer
and from this you get record where there is only one:
select a.* from (
select max(amount) mymax, min(amount) mymin, customer from table where
date = some_date group by customer
) a
where mymax = mymin
Thanks,
Zdravko Sonje
| |