Database: customers_and_invoices

Question: Show all product names and the total quantity ordered for each product name.
SQL: SELECT T2.product_name ,  sum(T1.product_quantity) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id  =  T2.product_id GROUP BY T2.product_name

Question: Show the order ids and the number of items in each order.
SQL: SELECT order_id ,  count(*) FROM Order_items GROUP BY order_id

Question: Show the product ids and the number of unique orders containing each product.
SQL: SELECT product_id ,  count(DISTINCT order_id) FROM Order_items GROUP BY product_id

Question: Show all product names and the number of order items on each product.
SQL: SELECT T2.product_name ,  count(*) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id  =  T2.product_id JOIN Orders AS T3 ON T3.order_id  =  T1.order_id GROUP BY T2.product_name

Question: Show order ids and the number of products in each order.
SQL: SELECT order_id ,  count(DISTINCT product_id) FROM Order_items GROUP BY order_id

Question: Show order ids and the total quantity in each order.
SQL: SELECT order_id ,  sum(product_quantity) FROM Order_items GROUP BY order_id