SQL Server を使用しています。
item_table
次のようなテーブルがあります。
item age
--------------
1 1
1 6
2 2
私はこのような他のテーブルを持っていますprice_table
:
item pricetype price
--------------------------
1 O 5
1 P 6
1 V 7
2 O 8
2 P 9
2 V 10
だから、私は2つのテーブルの上に内部結合したい.
select *
from item_table i
inner join price_table p
on ...
については、次の条件がありますon
。
- アイテムの平均年齢が より大きい場合、次の
3
ようにします。inner join price_table on pricetype = 'O' or pricetype = 'P'
- そうでない場合は、次のことを行います。
inner join price_table on pricetype = 'O' or pricetype = 'P' or pricetype = 'V'
だから条件には条件がありon
ます。
選択クエリを作成するにはどうすればよいですか?
編集:
条件を平均年齢に変更しましたが、代わりにtype