【问题标题】:SQL - get rows where one column is a certain percentage greater than anotherSQL - 获取一列比另一列大一定百分比的行
【发布时间】:2011-09-13 15:01:04
【问题描述】:

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

假设我有 2 列:

  • InventoryLevel int
  • InventoryAlert int

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

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

【问题讨论】:

    标签: sql sql-server-2008


    【解决方案1】:
    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. "*/
    

    【讨论】:

    • 谢谢,我很欣赏这个伟大的答案(和精神力量);)
    【解决方案2】:
    SELECT *
    FROM YourTable
    WHERE InventoryLevel = 1.25*InventoryAlert -- Or Maybe >= ?
    

    【讨论】:

    • @Martin Smith - 是的,我不知道它是否应该确切地增加 25%,或者超过 25%
    • 不错!打算试一试。如果 InventoryLevel 是任何大于 25% 的值,则不必精确。
    • @jyoseph - 哦,在那种情况下,我会取消删除我的答案,因为我必须从心理上知道这是要求。
    • @Martin Smith - 是的,你应该在那里回答。虽然我不得不承认你对 SQL 和精神力量有这么多的了解是不公平的
    猜你喜欢
    • 2020-01-25
    • 1970-01-01
    • 2020-11-23
    • 2021-10-26
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 2014-02-03
    相关资源
    最近更新 更多