SQL求解SELECT基础语句

问题遇到的现象和发生背景

题目如下
From the order_items table, get the items
for order #6
where the total price is greater than 30

问题相关代码,请勿粘贴截图

我的代码如下
SELECT *, quantity * unit_price AS total_price
FROM order_items
WHERE order_id=6 AND total_price > 30

运行结果及报错内容

Error Code: 1054. Unknown column 'total_price' in 'where clause'

我的解答思路和尝试过的方法

正确解法如下
SELECT *
FROM order_items
WHERE order_id = 6 AND total_price>30

我想要达到的结果

因为column没有总价格这一列,所以我想输出结果的时候也显示quantity * unit_price这个数值,但总是报错……

别名不能放到查询条件里面使用,修改如下:

SELECT *, quantity * unit_price AS total_price
FROM order_items
WHERE order_id=6 AND quantity * unit_price > 30

这样写就可以了

SELECT *, quantity * unit_price AS total_price
FROM order_items
WHERE order_id=6 AND quantity * unit_price > 30
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632