私は に不慣れOracle
で、知識がありMS SQL
ます。差出人に応じて電話番号を取得しようとしてuser_id
いTable2
ますが、ビジネスロジックは次のとおりです。
ケース 1: で 1 つの一致が見つかった場合は、
Table1
それぞれのフリーダイヤル番号を取得します。Table2
ケース 2: で一致するものが見つからない場合は
Table1
、デフォルトのフリーダイヤル番号を取得します。Table2
ケース 3: 複数の一致が見つかった場合、
Table1
それらすべてについて、 ordered byまたはから値をassigned_care_levels
取得し、一番上の行の電話番号を選択します。Care
Table2
asc
desc
個別に実行すると正常に動作する次のクエリを作成しました。ただし、 if else ステートメントを使用して結合すると、次のエラーが発生しますERROR: ORA-00907: missing right parenthesis
。これが私のコードです:
if ((select count(distinct care_level) from Table1 where user_id = '100') > 0)
select phone from Table2 where care_level in (select distinct care_level from Table1 where user_id = '100')
and rownum = 1
order by care_level asc
else if((select count(distinct care_level) from Table1 where user_id = '100') = 0)
select phone from Table2 where care_level = 'default'