0% found this document useful (0 votes)
19 views2 pages

HIT234 - Week 02 - Answers

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

HIT234 - Week 02 - Answers

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

HIT234 - Database Concepts

Tutorial session 2 – Week 2 -

Answer

Attempt to Answer ALL Tutorial questions below:

SECTION 1 - SINGLE TABLES QUERIES

Functions Count Sum Avg

1. Find the number of items

SELECT COUNT(*) FROM ITEM;

SELECT COUNT (ITEMNO) FROM ITEM;

SELECT ITEMNO FROM item GROUP BY ITEMNO;

2. Find the average ITEMPRICE of an

item SELECT AVG(ITEMITEMPRICE)

FROM ITEM;

3. Find the sum of all the item prices

SELECT SUM(ITEMPRICE) FROM ITEM;

4. Find the number of CUSTOMERs in each CUSTSTATE

SELECT COUNT(CUSTABN), CUSTSTATE

FROM CUSTOMER

GROUP BY CUSTSTATE;

More On Functions ( Max)

5. The maximum number sold for each item

SELECT ITEMNO, max(quantity) FROM INVOICEITEM GROUP BY ITEMNO ORDER BY ITEMNO;


6. The number of each item that has been sold

SELECT ITEMNO, sum(quantity) FROM INVOICEITEM GROUP BY ITEMNO ORDER BY ITEMNO;

SECTION 2 - MULTIPLE TABLE QUERIES

1. Find the customer name for invoice 12. Find their details.

- SELECT CUSTNAME FROM CUSTOMER c, INVOICE i

WHERE c.CUSTABN = i.CUSTABN AND i.INVOICENO = 12;

- SELECT c.* FROM CUSTOMER c, INVOICE i

WHERE c.CUSTABN = i.CUSTABN AND i.INVOICENO = 12;

2. Find the names of all customers who brought an item with Tube in its ITEMDESC

SELECT distinct c.CUSTNAME

FROM CUSTOMER c, INVOICE i, INVOICEITEM ii, ITEM it

WHERE c.CUSTABN = i.CUSTABN AND i.INVOICENO = ii.INVOICENO AND ii.ITEMNO =


it.ITEMNO AND it.ITEMDESC LIKE '%Tube%';

3. Find the CUSTOMERs who live in NSW or Qld who brought Screens

SELECT c.CUSTNAME

FROM CUSTOMER c, INVOICE I, INVOICEITEM ii,

ITEM it WHERE c.CUSTABN = i.CUSTABN

AND i.INVOICENO = ii.INVOICENO

AND ii.ITEMNO = it.ITEMNO AND it.ITEMDESC LIKE

'%Screen%'AND (c.CUSTSTATE= 'NSW' or c.CUSTSTATE

='Qld');

You might also like