Assignment 42
Assignment 42
Assignment 42
Q1: Consider the following Company database, describing the data of customer’s orders:
Write the appropriate SQL statements that perform the following queries: ( Solve part
10, 11 and 12, only when you finished all the previous queries to avoid changing the data. )
Important note: You must change the name of any manipulated column.
1) List the names of agents that placed an order for customer C003 or customer C006.
2) List all pair of products names that are in the same city, along with their city name.
3) List the number of orders and their total cost for each agent that handled orders with more
than $1,000 in total; showing the agent name.
4) List the names of all customers and the total cost of their orders if they have placed an
order.
5) List the id and the name of products that were not ordered through agents ’A04’.
6) List the id of products ordered by any agent who makes at least one order for a customer
in Kyoto.
7) List the id and discount percentage of customers who have the largest discount and those
who have the smallest discount.
8) List the id and name of agents with name beginning with the letter ‘J’ or ‘B’ and who do
not place orders for a Product located in Dallas.
9) List name of customers that ordered all the products.
10) Insert a new order for the customer that didn’t have any orders; with 1030 as order
number which has been placed in November by agent number ‘A01’ for product number
P06 with quantity of 90. Note: unknown values have to be selected from existing data.
12) Delete all orders placed by agents living in New York city.
Instructions:
This assignment should be solved using OracleXE DBMS (Database home page – SQL
worksheet). Your solution should include the input (query) as well as the output (result). If
you solve assignment without oracle DBMS you will get 0 as your mark.
Make sure to execute script in figure1 before executing the queries. The script in figure1
will create the DB schema for you and will also populate the tables with mock data. To
create the DB in your account, login to OracleXE DB Home Page, then copy and paste the
script shown in figure1 into your SQL interface and execute them. The first time that you
run the script, you will probably see some error messages indicating that the drop table
statements failed. You may ignore these messages. Note: In OracleXE you need to execute
each statement (which ends with ‘;’) separately.
Note: Figure2 shows the relations with its data that have been created in your account after
executing Figure1 script. You can check the correctness of the resulted table of your query
by checking these tables.
Figure 1: Company Database DDL statements.
Customer Agent
CID CNAME CITY DISCOUNT AID ANAME CITY PERCENT
C001 Tiptop Duluth 10 A01 SmithO New York 6
C002 Basics Dallas 12 A02 Jones Newark 6
C003 Allied Dallas 8 A03 Brown Tokyo 7
C004 ACME1 Duluth 8 A04 Gray New York 6
C005 Top1 Duluth 0 A05 Otasi Duluth 5
C006 ACME2 Kyoto 0 A06 SmithS Dallas 5
Product
PID PNAME CITY QUANTITY PRICE
P01 Comb Dallas 111400 .5
P02 Brush Newark 203000 .5
P03 Razor Duluth 150600 1
P04 Pen Duluth 125300 1
P05 Pencil Dallas 221400 1
P06 Folder Dallas 123100 2
P07 Case Newark 100500 1
Orders
ORDERNO MONTH CID AID PID ORDEREDQUANTITY COST
1011 January C001 A01 P01 1000 450
1012 January C001 A01 P01 1000 450
1019 February C001 A02 P02 400 180
1017 February C001 A06 P03 600 540
1018 February C001 A03 P04 600 540
1023 March C001 A04 P05 500 450
1022 March C001 A05 P06 400 720
1025 April C001 A05 P07 800 720
1013 January C002 A03 P03 1000 880
1026 May C002 A05 P03 800 704
1015 January C003 A03 P05 1200 1104
1014 January C003 A03 P05 1200 1104
1021 February C004 A06 P01 1000 460
1016 January C006 A01 P01 1000 500
1020 February C006 A03 P07 600 600
1024 March C006 A06 P01 800 400