You are on page 1of 10

1.

select sum(LINE_UNITS> from line group by INV_NUMBER;

Explanation: sum() is an aggregate function which returns addition of values. Here we


are extracting sum of LINE_UNITS which is one column in ‘line’ table for each invoice
i.e. INV_NUMBER.
2. select * from product where V_CODE=””;

Explanation: We are extracting details from ‘product’ table where V_CODE column
doesn’t hold any value.
3. select * from invoice where INV_SUBTOTAL > 24 and INV_SUBTOTAL<76;

Explanation: We are extracting details from ‘invoice’ table where the condition is that
INV_SUBTOTAL value should be greater than 24 and less than 76. With ‘and’ keyword
we can provide another condition. It will display the information of invoice if both the
conditions are satisfied.
4. select * from invoice where INV_SUBTOTAL = (select min(INV_SUBTOTAL) from
invoice);

Explanation: Here in sub-query, we are extracting minimum value of INV_SUBTOTAL


column of ‘invoice’ table. Then the main query will give you record where
INV_SUBTOATL value is minimum.
5. select v.V_CODE, v.V_NAME, from vendor v, product p where
v.V_CODE==p.V_CODE group by v.V_CODE;

Explanation: In ‘vendor’ and ‘product’ table, V_CODE column is common. V_CODE


holds the IDs of vendors in ‘vendor’ table. In ‘product’ table, V_CODE holds the IDs of
vendor who supplies that product. So the above query shows the code and names of
the vendors who supplied products.
6. select v.V_CODE, v.V_NAME from vendor v, product p, except select v.V_CODE,
v.V_NAME from vendor v, product p where v.V_CODE==p.V_CODE group by
v.V_CODE;

Explanation: In ‘vendor’ and ‘product’ table, V_CODE column is common. V_CODE


holds the IDs of vendors in ‘vendor’ table. In ‘product’ table, V_CODE holds the IDs of
vendor who supplies that product. So the above query shows the names and codes of
the vendors who did not supply any product using ‘except’ keyword.
7. select distinct(v.V_NAME), v.V_CODE from vendor v, product p where v.V_NAME
NOT IN (select v.V_NAME from vendor v, product p where
v.V_CODE==p.V_CODE;

Explanation: This query will give you same result as the 6th query, but here we have to
use ‘NOT IN’ keyword.
8. select v.V_CODE, v.V_NAME, count(p.V_CODE) as ‘TOTAL PRODUCTS SUPPLIED’
from vendor v, product p where v.V_CODE==p.V_CODE group by v.V_CODE;

Explanation: This query will display the information like code and name of a vendor
and total count of products each vendor has supplied. ‘count’ is an aggregate function
which gives number of occurrences.
9. select * from emp where EMP_AREACODE==615;

Explanation: This query extracts all the information from ‘emp’ table where
EMP_AREACODE is 615.
10.select p.P_CODE, p.P_DESCRIPT, p.P_INDATE, p.P_QOH, p.P_MIN, p.P_PRICE,
p.P_DISCOUNT, p.V_CODE from product p inner join line l on
p.P_CODE=l.P_CODE where l.LINE_PRIC> 99;

Explanation: Here we are displaying details of product where the line price that is
LINE_PRICE of line table is greater than 99. We have joined the table through inner join
on P_CODE column of ‘product’ table and P_CODE of ‘line’ table.

You might also like