乘以两列,在select语句sql中显示为新列

时间:2016-11-10 23:08:22

标签: mysql

尝试从两列中获取值,将它们相乘,并在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语句的最后一部分,它就会这样做:

select statement result without extra column error message

1 个答案:

答案 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 

但是,如果没有任何样本数据或预期输出的演示,那只是猜测。