尝试从两列中获取值,将它们相乘,并在select语句中将结果显示为新列。以下是我到目前为止的内容
select m.item_name, m.price, sum(od.qty) as count
from menu as m, order_detail as od, sum(m.price * od.qty) as tsales
where m.menuid = od.menuid
group by m.item_name
order by count desc
limit 10;
我可以让select语句执行所有操作但是显示带有新值的新列。如果没有select语句的最后一部分,它就会这样做:
答案 0 :(得分:0)
我认为我们正在寻找一个从这样的声明中返回的结果:
SELECT m.item_name
, SUM(m.price*od.qty) AS tot_price_times_qty
FROM menu m
JOIN order_detail od
ON od.menuid = m.menuid
GROUP BY m.item_name
ORDER BY tot_price_times_qty DESC
LIMIT 10
但是,如果没有任何样本数据或预期输出的演示,那只是猜测。