Oppolzer - Informatik / Blog


Blog-Hauptseite      Neuester Artikel      Älterer Artikel      Neuerer Artikel      Älterer gleiche Kategorie      Neuerer gleiche Kategorie

DB2-L - SQL-Beispiel: zu jedem Wert der nächste Wert

Subject:

Fwd: Regarding DB2 SQL Query

From:

Bernd Oppolzer <bernd.oppolzer@T-ONLINE.DE>

Reply-To:

DB2 List <db2-l@lists.idug.org>

Date:

2011.09.12 08:52:00


select t1.x, t2.x
from tablex t1, tablex t2
where t2.x = (select min (x)
from tablex
where x > t1.x)
union all
select max (x), 99999
from tablex

should do the same and should be less expensive,
esspecially if x is at the left side of an index,
then the whole thing will be index-only, I think.

Kind regards

Bernd


Am 11.09.2011 11:33, schrieb Bernd Oppolzer:
> couldn't try it, but maybe this will work:
>
> select t1.x, coalesce (min(t2.x), 99999)
> from tablex t1
> left join
> tablex t2
> on t1.x < t2.x2
> group by t1.x;
>
> Maybe a little expensive; maybe there is another solution
> using a correlated subquery. Every solution will have to take
> care about the situation where no bigger value is found.
>
> Kind regards
>
> Bernd
>
>

Blog-Hauptseite      Neuester Artikel      Älterer Artikel      Neuerer Artikel      Älterer gleiche Kategorie      Neuerer gleiche Kategorie