In: Computer Science
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking.
Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid: integer, pid: integer, amount: integer)
Output:
+--------------+ | pname | +--------------+ | Wooden Chair | +--------------+
Output: (Note: Order of rows does not matter.)
+-----------------+-------+ | cname | state | +-----------------+-------+ | Fred Smith | IL | | Joe Smithsonian | IA | | Steve Stevenson | IL | | Russell Johnson | CA | | John Doe | MI | | Scott Charles | CA | | Shannon Rose | MI | | Beth Rosebud | IA | | Suzanne May | IA | +-----------------+-------+
Output:
+-----+----------------+ | sid | Total_Shipment | +-----+----------------+ | 12 | 45.49 | | 8 | 98.75 | | 7 | 98.97 | | 10 | 104.00 | | 4 | 164.95 | | 6 | 183.96 | | 11 | 260.00 | | 3 | 659.80 | | 5 | 676.00 | | 9 | 1664.00 | +-----+----------------+
1) SELECT pname FROM product WHERE pname LIKE "%Ch%" AND price > AVG(price);
Note:
2)SELECT cname, state FROM Customer A, Customer B WHERE A.cid != B.cid AND A.state= B.state;
3)SELECT sid, price*amount AS "Total_Shipment" FROM Product, ShippedProduct WHERE Product.pid= ShippedProduct.pid ORDER BY price*amount asc;