题目如下
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
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!