简体   繁体   English

MYSQL - 获取 A 列小于 B 列的行

[英]MYSQL - get the rows where one column A is less than column B

Table (showing only relevant columns)表格(仅显示相关列)

ID | product_name | stock | stock_level
6  | test name    | 5     | 4
 7 | test name 2  | 3     | 9

I have a lot more rows in my database.我的数据库中有更多行。

In MYSQL, how can I get every row where the stock value is less than the stock_level value?在 MYSQL 中,如何获取股票值小于 stock_level 值的每一行?

Like this?像这样?

SELECT * FROM table WHERE stock < stock_level

That would return row2 (stock = 3, stock_level= 9) but not row1 (stock = 5, stock_level= 4).这将返回 row2 (stock = 3, stock_level= 9) 而不是 row1 (stock = 5, stock_level= 4)。

<?php
$result = mysqli_query($myslqi, "SELECT * FROM table WHERE stock < stock_level")) {
  ....
}

暂无
暂无

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

相关问题 如何获取WHERE列小于变量的行? - How to get rows WHERE column is less than variable? 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 MySql 获取其中一列等于另一列等于另一表中的另一列的行 - MySql get rows where one column equals to another colum in another table where one column is equal 获取其中一列值小于集合中感兴趣的行的最后一行 - get the last row of which one of its column value is less than the rows of interest within a set Mysql其中A列= X且B列= Y或B列= Z - Mysql Where Column A = X and Column B = Y and or Column B = Z 如果 B 列的值小于 700,则 phpspreadsheet 条件格式列 A - phpspreadsheet conditional format column A if value of column B is less than 700 Eloquent:获取列值(x)存在于多于一行的所有行(SQL DB) - Eloquent: Get all rows where column value(x) exists in more than one row (SQL DB) PHP MySQL:从表A获取行,其中表B的Z列中不存在表A的Z列的值 - PHP MySQL: Getting rows from table A where values of column Z of Table A not present in column Z of table B Mysql-使用A列和B列选择和分组行,其中A.value和B.value = x和y或y和x - Mysql - Select & Group rows with A column, and B column where A.value and B.value = x and y or y and x PHP MySQL如何获取列完全唯一的行数 - PHP MySQL How to get the count of rows where column is completely unique
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM