Sample SQL: CSC 436 - Fall 2003
Sample SQL: CSC 436 - Fall 2003
SELECT NAME
FROM TOY
5) Retrieve the name of every toy and the name of every
manufacturer.
SELECT *
FROM TOY
WHERE MAN_ID = ‘FP’
7) List the prices of all toys in the TOY relation.
SELECT MSRP
FROM TOY
(SELECT PNAME
FROM EMPLOYEE, WORKS_ON, PROJECT
WHERE LNAME=SMITH AND SSN=ESSN AND
PNO=PNUMBER)
UNION
( SELECT PNAME
FROM EMPLOYEE, DEPARTMENT, PROJECT
WHERE LNAME=SMITH AND SSN=MGRSSN AND
DNUMBER=DNUM)
9) Reformulate the above query as a nested query
SELECT DISTINCT PNUMBER
FROM PROJECT
WHERE PNUMBER IN (SELECT PNUMBER
FROM PROJECT, DEPARTMENT,
EMPLOYEE
WHERE DNUM=DNUMBER AND
MGRSSN=SSN AND
LNAME=SMITH)
OR
PNUMBER IN (SELECT PNO
FROM WORKS_ON, EMPLOYEE
WHERE ESSN=SSN AND
LNAME=SMITH)
10) Select the toy numbers of all toys that have the
same price and age group as the Farm House.
SELECT NAME
FROM TOY
WHERE MSRP > ALL (SELECT MSRP
FROM TOY
WHERE NAME=FARM HOUSE)
12) (from Company db) Retrieve the name of each employee
who has a dependent with the same first name and sex as the
employee.
SELECT NAME
FROM CUSTOMER C
WHERE NOT EXISTS (SELECT *
FROM ORDER
WHERE
C.CUST_NUM=ORDER.CUST_NUM
AND DELIV IS NULL)
15) Retrieve the names of all toys manufactured by FP or FY.
SELECT TOY_NAME
FROM TOY
WHERE MAN_ID IN (FP, FY)
16) Retrieve the names of customers who have never ordered
a toy from the catalog.
SELECT NAME
FROM CUSTOMER
WHERE LAST_ORDER_DATE IS NULL
17) Retrieve the toy names and the customer names for every
outstanding order for toys whose names fall in the first half of the
alphabet .
SELECT TOY_NUM
FROM (ORDER JOIN CUSTOMER ON
ORDER.CUST_NUM=CUSTOMER.CUST_NUM)
WHERE NAME=‘KAREN SMITH’
19) Find the average price of all toys in the TOY relation.
SELECT AVG(MSRP)
FROM TOY
20) Find the total number of toys orderd by and the total amount
of money spent by customer GEORGE GRANT.
SELECT NAME
FROM CUSTOMER
WHERE ADDRESS LIKE ‘%NY%
24) Show the new prices if Fischer Price raised their
MSRPs by 10%.