0

次のテーブル設定があります

Acc  Currency  Alias
1    NULL      A
1    USD       B
1    EUR       C

入力を。として指定してエイリアスを抽出したいと思いますAcc。およびは別のテーブルに結合されますCurrencyAcc

次のように動作するはずです-

If acc = 1 and currency is USD then B, if EUR then C, if null then A

誰かがこれを手伝ってもらえますか?

4

2 に答える 2

0

実際に自分で SQL を記述しようとしましたか?

SELECT ...
FROM otherTable ot
(INNER) JOIN thisTable tt
ON ot.Acc = tt.Acc AND ot.Currency = tt.Currency 
...
于 2012-11-01T17:42:19.193 に答える
0

NULL での明示的なマッチング

SELECT *
  FROM othertbl o
  JOIN thistbl t on o.acc = t.acc
                and (o.currency = t.currency or o.currency is null AND t.currency is null)

または、あなたの場合、NULL通貨をthistblフォールバックとして使用します

 SELECT ...
   FROM othertbl o
   JOIN thistbl t on o.acc = t.acc and o.currency = t.currency
  UNION ALL
 SELECT ...
   FROM othertbl o
   JOIN thistbl t on o.acc = t.acc and t.currency IS NULL
  WHERE NOT EXISTS (select *
                      from thistbl t2
                     where o.acc = t2.acc and o.currency = t2.currency)
于 2012-11-01T18:38:11.363 に答える