MINIMUM_AMOUNT、MAXIMUM_AMOUNT、および CURRENCY_ID を格納する SQL サーバーにテーブルがあります。ここで、挿入する新しい値がテーブルに既に存在することを確認する SQL クエリを組み立てたいと思います。例: 私のテーブルには次のように 2 つのレコードがあります
RANGE_ID MINIMUM_AMOUNT MAXIMUM_AMOUNT CURRENCY_ID
------------------------------------------------------------
1 3000 9000 3
2 12000 17000 3
ユーザーが新しいレコードを挿入するとき、すでに使用可能な値の間にあるべきではありません
つまり、ユーザーはこれらの値のペアを入力できないはずです
1 ) Min Amount : 4000 , Max Amount : 5000 ,Currency Id : 3
because this range already lies in the first record (RANGE_ID 1)
2) Min Amount : 8000 , Max Amount : 10000,Currency d : 3
because the minimum amount is already present in the range specified in first record (3000-9000)
3) Min Amount : 8000, Max Amount : 15000 , currency Id=3
because the minimum amount is already present in one range and the maximum amount is also present in another range
4) Min Amount : 2500 , Max Amount : 11000 ,Currency Id=3
because the this range overlaps with the data in first record
ユーザーは、異なる通貨 ID で上記の範囲を入力できる必要があります。
これを確認するために If Exists クエリを探しています。