この例のデータセットを考えると:
-----------------------------
| item | date | val |
-----------------------------
| apple | 2012-01-11 | 15 |
| apple | 2012-02-12 | 19 |
| apple | 2012-03-13 | 7 |
| apple | 2012-04-14 | 6 |
| orange | 2012-01-11 | 15 |
| orange | 2012-02-12 | 8 |
| orange | 2012-03-13 | 11 |
| orange | 2012-04-14 | 9 |
| peach | 2012-03-13 | 5 |
| peach | 2012-04-14 | 15 |
-----------------------------
各itemについて、valがCONST=10を下回った最初の日付を、後で上に戻ることなく選択するクエリを探しています。この例では、次のようになります。
-----------------------------
| item | date | val |
-----------------------------
| apple | 2012-03-13 | 7 |
| orange | 2012-04-14 | 9 |
-----------------------------
これは、カーソルを使用しなくても可能ですか? これをSybaseで探しています。
カーソルがないとこれができない場合は、プログラミング言語でレコードを処理できます。ただし、その場合、私の実際の使用例では完全な履歴が非常に長いため、最終的に求めているレコードを計算するために「十分な」レコードを選択する「適切な」クエリが必要です: valがCONSTを下回った最新のレコードその上に戻ることなく。