如何在mysql中解析嵌套select的值

时间:2012-03-29 11:33:18

标签: mysql

我想将parsed_param传递给嵌套选择。像这样。

select name ,ord.sq,ord.sp ,sandwich_id as parsed_param 
from sandwiches , (select sum(quantity) as sq, sum(total_price) as sp 
                   from order_sandwiches 
                   where sandwich_code=parsed_param) as ord

   order by parsed_param

1 个答案:

答案 0 :(得分:2)

试试这个

SELECT sandwiches.name,
  sandwiches.sandwich_id,
  sum(order_sandwiches.quantity) as sq,
  sum(order_sandwiches.total_price) as sp
FROM sandwiches
JOIN order_sandwiches ON order_sandwiches.sandwich_code = sandwiches.sandwich_id
GROUP BY sandwiches.name, sandwiches.sandwich_id
ORDER BY sandwiches.sandwich_id