gpt4 book ai didi

MySQL AS 语句生成错误

转载 作者:行者123 更新时间:2023-11-29 12:51:10 24 4
gpt4 key购买 nike

我正在阅读 Murach MySQL 书,但无法运行第 3 章中的练习之一,我不知道出了什么问题。 discount_amount 列导致:

ERROR 1054 (42S22): Unknown column 'list_price' in 'field list'

这就是我使用 AS 的原因。有人看到我的代码有什么问题吗?

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;

最佳答案

需要在ROUND中再次计算

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;

关于MySQL AS 语句生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24706982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com