SQL - 获取一列比某个列大一定百分比的行

时间:2011-09-13 15:01:05

标签: sql sql-server-2008

我需要获取一列比某个列大一定百分比的行。

所以说我有两列:

  • InventoryLevel int
  • InventoryAlert int

我需要获取InventoryLevelInventoryAlert大25%的所有行。

这可以在一个查询中完成所有操作吗?任何帮助将不胜感激!

2 个答案:

答案 0 :(得分: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 :(得分:4)

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