简体   繁体   English

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

[英]SQL - get rows where one column is a certain percentage greater than another

I need to get rows where one column is a certain percentage greater than another. 我需要得到一列,其中一列比另一列高一定百分比。

So say I have 2 columns: 所以说我有2列:

  • InventoryLevel int
  • InventoryAlert int

I need to get all rows where the InventoryLevel is 25% greater than the InventoryAlert . 我需要获得InventoryLevelInventoryAlert大25%的所有行。

Is that possible to do all in one query? 这可以在一个查询中完成所有操作吗? Any help would be greatly appreciated! 任何帮助将不胜感激!

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. "*/
SELECT *
FROM YourTable
WHERE InventoryLevel = 1.25*InventoryAlert -- Or Maybe >= ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL - 选择一列比同一日期的其他列大的行 - SQL - Select rows where one column is greater than other column on the same date 查找其中一个字段大于另一字段的行 - Find rows where one field is greater than another one SQL —是否有任何行的列值大于6? - SQL — Are there are any rows where a column value is greater than 6? 当其中一列和另一列大于 - SQL select distinct when one column in and another column greater than MySql获取id = xxx且id相同的行中其他表中的最新列大于一个的所有行 - MySql get all rows where id = xxx and where the newest column in other table in row with same id is greater than one Oracle SQL - select 查询条件大于时间戳列中定义的特定时刻 - Oracle SQL - select query with where condition greater than certain moment defined in a timestamp column SQL-Sqlite查询:获取一个数字大于另一个数字的字段,如果小于3且第一个数字完整,则始终为3 - SQL - Sqlite Query: obtain the fields where one number is greater than another, if less than 3 complete with the first, always 3 MYSQL - 获取 A 列小于 B 列的行 - MYSQL - get the rows where one column A is less than column B SQL查询:获取某些列的值最大的行 - SQL Query: Get rows where value of certain column is maximum 计算值大于或等于SQL中另一列的值的行数 - Counting the number of rows with a value greater than or equal to a value from another column in SQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM