In: Computer Science
List customer id, customer full name (Last name, full name, state) for those customers that have ordered more than once.
List customers (order id, customer id, and customer last name)
that had more than 2
-- products in their order. Order your result based on customer id
followed by order id
SQL SERVER DATABASE
1)
Solution)
SELECT c.customerId,CONCAT(c.customerLastname," ",c.customerFirstname) AS customerFullname,c.state FROM customer c WHERE customerId IN ( SELECT customerId FROM order GROUP BY customerId HAVING COUNT(*) > 1);
Explanation:Subquery is used to fetch the records from order table that have more than one customerId and then select that records from the customer table using the In.
2)
Solution)
SELECT o.orderId,c.customerId,c.customerLastname FROM customer c INNER JOIN order o ON c.customerId=o.customerId WHERE o.quantity>2 ORDER BY c.customerId,o.orderId;
Explanation:I have used inner join on customer and order to find the matching customer id and have used the where clause to find order having quantity greater than 2 and order the result by customerId and orderId
NOTE:Please change the column names as you have not provided them correctly and please upvote if you liked my answer and comment if you need any modification or explanation.