2011-09-13 4 views
2

ある列が別の列よりも一定割合大きい行を取得する必要があります。SQL - 1つの列が別の列よりも一定の割合を持つ行を取得する

は、だから私は2列を持っていると言う:

  • InventoryLevel int
  • InventoryAlert int

私はInventoryLevelInventoryAlertより25%大きいすべての行を取得する必要があります。

1つのクエリですべてを行うことは可能ですか?どんな助けでも大歓迎です!

答えて

7
SELECT InventoryLevel, 
     InventoryAlert 
FROM YourTable 
WHERE InventoryLevel > 1.25 * InventoryAlert 
/*Incorrect for stated question but meets clarification in comment 
    "InventoryLevel is any value greater than 25%, doesn't have to be exact. "*/ 
+1

おかげで、私は偉大な答え(と霊魂力を)感謝;) – jyoseph

4
SELECT * 
FROM YourTable 
WHERE InventoryLevel = 1.25*InventoryAlert -- Or Maybe >= ? 
+0

+1私の答えは、に見えたとして質問は、実際に「25%大きい」ない「25%を超える大きな」と言うん想定! –

+0

@マーティンスミス - うん、ちょうど**正確に** 25%以上、25%以上が良いかどうかわからなかった – Lamak

+0

ニース!これを打つつもりです。 InventoryLevelが25%を超える値であれば、正確である必要はありません。 – jyoseph

関連する問題