Subject | Re: [ib-support] "token unknown 'order' " |
---|---|
Author | Svein Erling Tysvær |
Post date | 2002-04-29T08:04:08Z |
To sum the last date:
select sum(a.qty) from mv_li a
where not exists (select 1 from mv_li b
where b.d_mov > a.d_mov)
or if you want the second last date(as your other mails may indicate):
select sum(a.qty) from mv_li a
where not exists (select 1 from mv_li b
where b.d_mov > a.d_mov
and exists(select 1 from mv_li c
where c.d_mov > b.d_mov))
and exists (select 1 from mv_li d
where d.d_mov > a.d_mov)
The first half checks that there is no future date that is not the newest
date in your table, whereas the second half checks that it isn't the most
recent date.
So, in your case you don't need any order by in the subselect.
HTH,
Set
select sum(a.qty) from mv_li a
where not exists (select 1 from mv_li b
where b.d_mov > a.d_mov)
or if you want the second last date(as your other mails may indicate):
select sum(a.qty) from mv_li a
where not exists (select 1 from mv_li b
where b.d_mov > a.d_mov
and exists(select 1 from mv_li c
where c.d_mov > b.d_mov))
and exists (select 1 from mv_li d
where d.d_mov > a.d_mov)
The first half checks that there is no future date that is not the newest
date in your table, whereas the second half checks that it isn't the most
recent date.
So, in your case you don't need any order by in the subselect.
HTH,
Set