[英]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
. 我需要获得InventoryLevel
比InventoryAlert
大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.