· 8 years ago · May 22, 2018, 03:40 AM
11.
2SELECT * FROM `products` WHERE products.productCode LIKE 'S24%' AND products.MSRP >= 50.0 AND products.MSRP <= 200.0 ORDER BY products.buyPrice LIMIT 5
3
42.
5SELECT orders.orderNumber, orders.orderDate, orders.requiredDate, IF(orders.comments IS NULL, 'NULL', SUBSTRING(orders.comments, 1, 20)) shortComment FROM `orders` WHERE orders.orderDate < '2003-04-01' AND orders.orderDate > '2002-12-31' AND DATEDIFF(orders.requiredDate, orders.orderDate) >= 5
6
73.
8 SELECT c.customerName, SUM(od.priceEach * od.quantityOrdered) AS total
9 FROM customers AS c
10 INNER JOIN orders AS o ON c.customerNumber = o.customerNumber
11 INNER JOIN orderdetails AS od ON od.orderNumber = o.orderNumber
12 WHERE SUBSTRING_INDEX(c.customerName," ", -1) NOT IN ("Co", "Co.", "Ltd", "Ltd.", "Inc", "Inc.")
13 GROUP BY c.customerNumber
14 HAVING total > 150000
15
164.
17SELECT *
18FROM customers AS c
19WHERE (
20 (SELECT SUM(od.quantityOrdered * od.priceEach) FROM orderdetails AS od INNER JOIN orders AS o ON od.orderNumber = o.orderNumber WHERE o.customerNumber = c.customerNumber) -
21 (SELECT SUM(p.amount) FROM payments AS p WHERE p.customerNumber = c.customerNumber)
22) > 50000 AND (SELECT SUM(p.amount) FROM payments AS p WHERE p.customerNumber = c.customerNumber) < 80000
23
245.
25
26CREATE TABLE IF NOT EXISTS new_products LIkE products;
27INSERT INTO new_products
28SELECT *
29FROM products
30WHERE productLine = "Planes";
31SELECT *
32FROM new_products;