You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATETABLEorder_details (
order_id INT,
product_id INT,
quantity INT
);
SELECTc.name,
c.region,
(SELECT category
FROM (
SELECTp.category, COUNT(*) as order_count
FROM orders o
JOIN order_details od ONo.order_id=od.order_idJOIN products p ONod.product_id=p.product_idWHEREo.customer_id=c.customer_idGROUP BYp.categoryORDER BY order_count DESCLIMIT1
) as most_ordered_category
) as favorite_category,
(SELECTAVG(price)
FROM products
WHERE category = (
SELECT category
FROM (
SELECTp.categoryFROM orders o
JOIN order_details od ONo.order_id=od.order_idJOIN products p ONod.product_id=p.product_idWHEREo.customer_id=c.customer_idGROUP BYp.categoryORDER BYCOUNT(*) DESCLIMIT1
) as sub_query
)
) as avg_price_of_favorite_category
FROM customers c
WHEREc.region='特定地区';
The text was updated successfully, but these errors were encountered:
Summary
The text was updated successfully, but these errors were encountered: