Mysql Can';t计算总价>;30

Mysql Can';t计算总价>;30,mysql,Mysql,对于订单项目表,获取订单#6中总价大于30的项目 USE sql_store; { SELECT order_id, product_id,quantity, unit_price, quantity*unit_price AS total_price FROM order_items WHERE order_id = 6 AND total_price > 30 } 错误代码:将数学表达式放在括号中: SELECT order_id, product_id,quantity,

对于订单项目表,获取订单#6中总价大于30的项目

USE sql_store;

{ SELECT order_id, product_id,quantity, unit_price,
quantity*unit_price AS total_price

FROM order_items
WHERE order_id = 6 AND total_price > 30

} 

错误代码:

将数学表达式放在括号中:

SELECT order_id, product_id,quantity, unit_price, (quantity*unit_price)
FROM order_items 
WHERE order_id = 6 AND (quantity*unit_price) > 30
卡尔几乎是对的

SELECT order_id
     , product_id
     , quantity
     , unit_price
     , quantity*unit_price subtotal
  FROM order_items 
 WHERE order_id = 6 
   AND quantity*unit_price > 30

您也可以说
小计>30
,但这会降低效率

欢迎这样做。请通过编辑问题将
SHOW CREATE TABLE{tablename}
作为文本和实际错误代码包括在内,这是正确的,但是如果我需要在输出窗口中添加另一列作为总价,而不是数量*单价,该怎么办,您想在数据库的新列中以编程方式填充一些值吗?或者您只想将“total_price”用作此查询的别名?要将total_price用作别名并在数据库中作为新列输出,您可以这样做:(quantity*unit_price as total_price)然后在order_id=6且total_price>30的情况下,注意:它实际上不会在数据库表中创建物理新列,但允许您将其用作“虚拟”返回列我看不出括号的相关性为什么命令数量*单价重复。。。为什么我们不能在where子句中使用小计。。。。