select
p.product_id,
p.name,
(select count(*) from order_items oi where oi.product_id = p.product_id) as orders,
if ((select count(*) from order_items oi where oi.product_id = p.product_id) > 1, 'Many times', 'Once') as frequency
from products p
group by product_id, name
方式二:
select
temp.product_id,
temp.name,
temp.orders,
if (tmep.orders>1, 'Many times', 'Once') as frequency
from(
select
p.product_id,
p.name,
(select count(*) from order_items oi where oi.product_id = p.product_id) as orders
from products p
group by product_id, name
) temp