Question
How to do solve the problems with the table data below? Please note: if the answer is a SELECT statement, print the statement and the
How to do solve the problems with the table data below?
Please note: if the answer is a SELECT statement, print the statement and the output; if the answer is an INSERT, UPDATE, or DETELE statement, print the statement and, the data before and after the statement is run.
1.Create a command to list all products from order_detail table (also called order line items table, same hereafter). But dont list any product more than once in the report.
2.Create a command to list all products in the order_detail table, except product Bike31A.
3.Create a command to list all order line items in order_detail table that are bikes, and only bikes.
4.Create a command to list all red bikes and only red bikes in the order_detail table. (Reason for saying "only" is that some students may create a command that lists all bikes, and then say, "but the red ones are in there".)
5.Create a command to list all bikes in the order_detail table that are red or blue, and only red and blue bikes. (The reason for saying "only" is the same as in previous question.)
6.Select the minimum price from order_detail table.
7.Select the oldest date from orders table;
8.Create a report of all orders that were recorded between 2004-01-11 and 2004-01-23. Your supervisor wants to read your SQL statement (as well as the report), so do use the BETWEEN keyword to impress him.
9.Create a report of all line items that have
Bike28A
Helmet
Bike28Schwinn
10.Your supervisor likes good SQL statements, so use as simple SQL as possible. (Hint: use the IN keyword)
11.Write a report of all orders that have no salesrep recorded.
12.Your supervisor wants a count of bikes ordered.
13.Your supervisor wants a count of the different kinds of bikes sold. (Hint: use Distinct)
14.Your supervisor wants to know the minimum qty*unitprice of any line items in the database; also the maximum qty*unitprice.
Write a report of all products sold, with the count of each product. But wherever there was only ONE unit of a product sold, leave it off the report. (Hint: you will need Group By and Having clause. You need only the order_detail table.)
Table data:
drop table if exists customer; drop table if exists orders; drop table if exists order_detail; drop table if exists product; drop table if exists salesrep; CREATE TABLE Customer (Fname varchar(10), LName varchar(20), AcctNum varchar(4) ); load data local infile '/tmp/data-customer.txt' into table Customer; CREATE TABLE Orders (AcctNum varchar(4), OrderNum integer, OrderDate DATE, StoreNum varchar(10), SalesRepNum varchar(1) ); load data local infile '/tmp/data-orders.txt' into table orders; create table Order_Detail (OrderNum integer, LineNum integer, ProdNum varchar(21), Qty integer, Color varchar(6), UnitPrice decimal(10,2) ); load data local infile '/tmp/data-orderdetail.txt' into table order_detail; create table Product (ProdNum varchar(21), ProdName varchar(23), ProdSupy varchar(13), ColorGrp varchar(8), ProdCost decimal ); load data local infile '/tmp/data-product.txt' into table Product; create table SalesRep (SalesRepNum varchar(1), SalesFName varchar(5), SalesLName varchar(9), SalesSSN varchar(11), SalesHDate DATE, SalesHRate integer, SalesBonus decimal(10,2) ); load data local infile '/tmp/data-salesrep.txt' into table SalesRep; select * from customer; select * from orders; select * from order_detail; select * from product; select * from salesrep;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started