2016-06-29 7 views
0

I以下のSQLを選択し、問題があります。SQL:2列が等しい場合を選択し、他の1列を選択し、両方の

は、私が2列positive thresholdnegative threshold持っている(名前のようないくつかの他の列の間を、IDS ....) 。

  • 彼らの(絶対)値が同じである場合には(-1で乗算)、私は列[threshold]としてのみ正の閾値を選択します。

  • 値が異なる場合は、[positiveThreshold][negativeThreshold]の2つの列を選択します。

ありがとうございます。

+5

SQLステートメントは固定列セットを返し、各行は同じ列を持つ必要があります。サンプルデータと必要な結果を提供してください。 –

答えて

1
select null as [threshold], positivethreshold, negativethreshold 
from table 
where negativethreshold is null 
or (positivethreshold + negativethreshold) <> 0 
union 
select positivethreshold, null, null 
from table 
where (positivethreshold + negativethreshold) = 0 
関連する問題