Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL AS语句生成错误_Mysql - Fatal编程技术网

MySQL AS语句生成错误

MySQL AS语句生成错误,mysql,Mysql,我正在阅读Murach MySQL的书,我无法从第3章中得到一个练习,我不知道出了什么问题。“折扣金额”列导致: ERROR 1054 (42S22): Unknown column 'list_price' in 'field list' 这就是我为什么用它来当老师的原因。有人看到我的代码有什么问题吗 SELECT product_name, list_price, discount_percent, list_price*discount_percent AS disco

我正在阅读Murach MySQL的书,我无法从第3章中得到一个练习,我不知道出了什么问题。“折扣金额”列导致:

ERROR 1054 (42S22): Unknown column 'list_price' in 'field list'
这就是我为什么用它来当老师的原因。有人看到我的代码有什么问题吗

SELECT product_name,
   list_price,
   discount_percent,
   list_price*discount_percent AS discount_amount,
   list_price-discount_amount AS discount_price,
   ROUND(discount_amount, 2),
   ROUND(discount_price, 2)
FROM products
ORDER BY discount_price DESC
LIMIT 5;

需要重新计算一次吗

SELECT product_name,
   list_price,
   discount_percent,
   list_price*discount_percent AS discount_amount,
   list_price-discount_amount AS discount_price,
   ROUND(list_price*discount_percent, 2),
   ROUND(list_price-discount_amount, 2)
FROM products
ORDER BY discount_price DESC
LIMIT 5;

我试过了,但还是犯了同样的错误。这完全是有道理的,我真的很想这样做。@lioness什么是标价?我明白了!从产品订单中选择产品名称、标价、折扣百分比、标价*折扣百分比作为折扣金额、标价-(标价*折扣百分比)作为折扣价格、四舍五入(标价*折扣百分比,2)、四舍五入(标价-(标价*折扣百分比),2)按折扣价格说明限制5;伟大的很高兴你能让它工作!差不多了:)