我想将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
答案 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