Sunteți pe pagina 1din 23

ASSIGNMENT -2

2.1. Table Name : client_master


Description : use to store information about clients

Column Name Data Type Size Attributes


client_no Varchar 6 Primary key/first letter must start with ‘C’/not
null
name Varchar 20 not null
address1 Varchar 30 not null
address2 Varchar 30
city Varchar 15
state Varchar 15
pincode number 6
bal_due money 10
 For creating database: company

 For creating table : client_master


 For inserting values to a table:

 Data Output:
Select * FROM client_master;

2.2. Table name : Product_master


Description : Used to store information about products

Column name Data type Size Attributes


Product_no Varchar 6 Primary key/first letter must start with ‘P’
Description Varchar 5 Not null
Profit_percent int 3 Not null
Unit_measure Varchar 10 Not null
Qty_on_hand Int 8 Not null
Recorder_lvl Int 8 Not null
Sell_price money 10 Not null,cannot be 0
Cost_price money 10 Not null,cannot be 0
 For creating table : product_master

 For inserting values to a table:

 Data Output:
Select * FROM product_master;
2.3. Table name : Salesman_master
Description : Used to store information about salesman working in the company

Column Name Datatype Size Constraints


salesman_no varchar 6 Primary Key/first letter must start with ‘S’
salesman_nam varchar 20 Not Null
e
address1 varchar 30 Not Null
address2 Varchar 30
city varchar 20
pincode number 6
state varchar 20
sal_amt money 8
tgt_to_get number 6 Not null,cannot be 0
ytd_sales int 6 Not Null, cannot be 0
remarks varchar 60 Not Null

 For creating table:salesman_master

 For inserting values to a table


 Data Output:
Select * FROM salesman_master;

2.4. Table name : sales_order


Description : Used to store information about order

Column Name Datatype Size Constraints


S_Order_No Char 6 Primary Key
S_OrderDate Date Not Null
Client_No Char 6 Foreign Key References Client_No of
Client_Master Table
dely_addr Varchar 25
Salesman_No Char 6 Foreign Key References Salesman_No of
Salesman_Master Table
delyType Char 1 Delivery: part(P)/full(F) /default will be F
billed_yn Char 1
dely_date Date Cannot be less than OrderDate
Order_Status Varchar 10 Values(‘In process’, ‘Fulfilled’, ‘Backorder’,
‘Cancelled’)

 For creating table: sales_order


 For inserting values to a table:

 Data Output:
SELECT * FROM sales_order;

2.5. Table name : sales_order_details


Description : Used to store information about products ordered

Column Data type Size attributes


s_order_no varchar 6 Primary key/ Foreign key references s_order_no of
sales_order table
Product_no varchar 6 Foreign key references product_no of product_master
table
Qty_ordered Int 8
Qty_disp Int 8
Product_rate money 10

 For creating table:sales_order_details


 For inserting values to a table:

 Data Output:
SELECT * FROM sales_order_details;

2.6. Table name : challan_header


Description : Used to store information about challan

Column Data type Size Attributes


challan_no Varchar 6 Primary key
s_order_no Varchar 6 Foreign key references s_order_no of
sales_order table
challan_date Date
Billed_yn char 1 Values(‘y’,’n’)

 For creating table :challan_header


 For inserting values to a table:

 Data Output:
Select * from challan_header;

2.7. Table name : challan_details


Description : Used to store information about challan details

Column name Data type Size Attributes


Challan_no Varchar 6 Primary key/foreign key references challan_no
of challan table
Product_no varchar 6 Primary key/foreign key references
product_no of product_master table
qty_disp int 4 Not null

 For creating table:challan_details

 For inserting values to a table


 Data Output
SELECT * FROM challan_details;

Queries:

1. Find out the name of all client .


SELECT name FROM client_master;

2. Print the entire client_master table .


SELECT * FROM client_master;
3. Retrieve the list of name and the cities of all the client .
SELECT name,city FROM client_master;

4. List the various products available products from the product_master table .
SELECT description FROM product_master;

5. Find the list of all client having “a” as the second letter in the names.
SELECT name FROM client_master where name LIKE ‘_a%d’;
6. Find out the client who stay in city whose second letter is “o”.
SELECT name FROM client_master where city LIKE ‘_o%d’;

7. Find the list of all clients who stay in city ‘Jodhpur’ or ‘Hisar’.
SELECT name FROM client_master where (city = ‘Jodhpur’) OR (city
=‘Hisar’);

8. List all the clients who located in ‘Jodhpur’.


SELECT name FROM client_master where city =‘Jodhpur’;

9. Print the list of clients whose bal_due are greater then value 3000.
SELECT name FROM client_master WHERE bal_due > cast(3000 as money);

10. Print the information from sales_order table of order placed in the month of Jan.
SELECT * FROM sales_order WHERE EXTRACT(MONTH FROM s_order_date) =
'01';
11.Display the order information for the Client no’C00001’ and ‘C00002’.

select s_order_no,s_order_date from sales_order where client_no


in('C00001','C00002');

12.Find the Product whose description as HDD and Mouse .

SELECT description FROM product_master where (description = ‘Mouse’) OR (description =


’Hdd’);

13.Find the product whose selling price is greater than 2000 and less then or equal to 5000.
SELECT DESCRIPTION FROM PRODUCT_MASTER WHERE SELLPRICE > 2000 AND
SELLPRICE <= 5000;
14.Find the product whose selling price is more than 1500 and also find the new selling price as original
price*15.Rename the column in the above querry as new_price.
SELECT description, sell_price*0.15 "NEW_PRICE" FROM product_master
WHERE sell_price > cast(5000 as money);

15.Find the product whose cost_price is less than 1500.


SELECT description FROM product_master where cost_price < CAST(1500
as money);

16. List the product in the shorted order of their description.


SELECT description FROM product_master ORDER BY description;
17.Calculate the square root of the price of each product.
SELECT sqrt (sell_price::numeric) "SQRT(sell_price)" ,
sqrt(cost_price::numeric) "SQRT(cost_price)" from product_master;

18.Divide the cost of product HD by difference between its price and 100.
select (cost_price::numeric/sell_price::numeric-100) as "divide"
FROM product_master where description='Hdd';

19.List the name, city and state of client not in the state of Hariyana.
SELECT name, city,state FROM client_master where NOT
State='Haryana';

20.List the product_no, description, sell_price of product whose description begin with letter ”M”.
SELECT product_no,description,sell_price FROM product_master where
description LIKE 'M%';
21.List all the order that were cancelled in the month of “January”.
SELECT * from sales_order where order_status='Canceled' and
EXTRACT(MONTH FROM dely_date)='01';

22.Count the total number of orders.


SELECT count(*) from sales_order;

23.Calculate the average price of all the products.


SELECT AVG(SELL_PRICE :: numeric) "avg(sell_price)", AVG(COST_PRICE
:: numeric) "avg(cost_price)" FROM PRODUCT_MASTER;

24.Calculate the minimum price of product.


SELECT min(sell_price) "minimum(sell_price)" ,min(cost_price)
"minimum(cost_price)" FROM product_master;
25.Determine the maximum and munimun product price. Rename the title as max_price and min_price
respectively.
SELECT min(sell_price) "min_price" ,max(sell_price) "max_price"
FROM product_master;

26. Count the number of product whose qty_on_hand is less than or equl to 1500.
SELECT DESCRIPTION FROM PRODUCT_MASTER WHERE qty_on_hand < 100;

27.Count the number of product whose qty_on_hand is less than reorder level.
SELECT DESCRIPTION FROM PRODUCT_MASTER WHERE qty_on_hand <
reorder_lvl;

::NO ROWS SELECTED

28. Printthe information of client_master,sales_order table in the following formate for all the
records:-
{Cust_name} has placed order {order_no} on {s_order_date}.
select name|| ' has placed an order ' || s_order_no || ' on ' ||
s_order_date "Information" from client_master, sales_order where
sales_order.client_no=client_master.client_no;
29.Print the description and total quantity soled for each product?
select description, sum(qty_order) FROM product_master p,
sales_order_details s where p.product_no=s.product_no group by
s.product_no,p.description;

30. Find the value of each product sold?


select s.product_no,p.description,sum(s.qty_disp*s.product_rate)
"Sales Per Product" from
sales_order_details s,product_master p where
p.product_no=s.product_no
group by s.product_no,p.description;
31.Calculate the avg quantity sold for each client the has a maximum order value of 15000?
select c.client_no,c.name, avg(s.qty_disp) "Avg. Sales"
,max(s.qty_order*s.product_rate::numeric) from sales_order_details
s ,sales_order so,client_master c
where c.client_no=so.client_no and so.s_order_no=s.s_order_no
group by c.client_no,c.name having
max(s.qty_order*s.product_rate::numeric)>15000;

32. Find out the total sales amount receivable for the month of jan.it will be the sum total of all the
billed order for the month?
select s.s_order_no,s.s_order_date,
sum(so.qty_order*so.product_rate::numeric) "Order
Billed",sum(so.qty_disp*so.product_rate) "Total Amount" from
sales_order s, sales_order_details so
where so.s_order_no=s.s_order_no and s.billed_yn='Y' and
to_char(s_order_date,'mon')='jan'
group by s.s_order_no,s.s_order_date;
33.Print the information of product_master,order_details table in the following formate for all the
records:-
{description} worth rs. {total sales for the product} was sold.

select p.description||' Worth Rs '||sum(d.qty_disp*d.product_rate)


from product_master p, sales_order_details d
where p.product_no=d.product_no group by p.description;

34.Print the information of product_master,order_details table in the following formate for all the
records:- {description} worth rs. {total sales for the product} was ordered in the month of
{s_order_date in month format}.
select p.description||' Worth Rs
'||sum(d.qty_disp*d.product_rate)||' was ordered in the month of
'||to_char(s_order_date,'month')"Description Total amount Month"
from product_master p, sales_order_details d,sales_order s
where p.product_no=d.product_no and s.s_order_no=d.s_order_no group
by p.description,s.s_order_date;

35.Find out the product which has been sold to ‘Ravi‘?


SELECT SOD.product_no, PM.description FROM sales_order_details SOD,
product_master PM, sales_ordeR SO, client_master CM WHERE
PM.product_no = SOD.product_no AND SO.s_order_no = SOD.s_order_no
AND CM.client_no = SO.client_no AND CM.name = 'Ravi';

36.Find out the product and their quantities that will have to delivered in the current month?
SELECT SOD.PRODUCT_NO, PM.DESCRIPTION, SUM(SOD.qty_order)
FROM SALES_ORDER_DETAILS SOD, SALES_ORDER SO, PRODUCT_MASTER PM
WHERE PM.PRODUCT_NO = SOD.PRODUCT_NO AND SO.s_order_no =
SOD.s_order_no AND TO_CHAR(DELy_DATE, 'MON-YY') =
TO_CHAR(CURRENT_DATE,'MON-YY') GROUP BY SOD.PRODUCT_NO,
PM.DESCRIPTION;

37.Find the product_no and description of moving products?


SELECT DISTINCT PRODUCT_MASTER.PRODUCT_NO, DESCRIPTION
FROM SALES_ORDER_DETAILS, PRODUCT_MASTER
WHERE PRODUCT_MASTER.PRODUCT_NO = SALES_ORDER_DETAILS.PRODUCT_NO;

38. Find the name of the client who have purchased ‘Floppies’?
SELECT DISTINCT SO.client_no, CM.name FROM sales_order_details SOD,
sales_order SO, product_master PM, client_master CM WHERE
PM.product_no = SOD.product_no AND SO.s_order_no = SOD.s_order_no
AND CM.client_no = SO.client_no AND description = 'Floppies';

39.List the product_no and s_order_no of customers having qty_ordered less than 5 from the order
details table for the product ‘FLoppies’?
SELECT sod.product_no,sod.s_order_no from sales_order_details
sod,product_master pm
WHERE sod.product_no=pm.product_no AND sod.qty_order<5 AND
description='Floppies';

40. Find the product and their quantities for the orders placed by ‘Rakhi’ and ‘Rinki’?
SELECT SOD.product_no, CM.name,PM.description,SUM(qty_order)
"UNITSORDERED"
FROM sales_order_details SOD, sales_order SO, product_master PM,
client_master CM
WHERE SO.s_order_no = SOD.s_order_no AND PM.product_no =
SOD.product_no AND CM.client_no = SO.client_no
AND (CM.name = 'Divya' OR CM.name = 'Shanu') GROUP BY
SOD.product_no, PM.description ,CM.name;
41.Find the product and their quantities for the orders placed by client_no ‘C00001’ and ‘C00002’?
SELECT SO.client_no, SOD.product_no, PM.description, SUM(Qty_order)
UNITSORDERED
FROM sales_order SO, sales_order_details SOD, product_master PM,
client_master CM
WHERE SO.s_order_no = SOD.s_order_no AND SOD.product_no =
PM.product_no AND SO.client_no = CM.client_no
GROUP BY SO.client_no, SOD.product_no, PM.description
HAVING SO.client_no = 'C00001' OR SO.client_no = 'C00002';

42.Find the product_no and description of non-moving products?


SELECT Product_no, description
FROM product_master
WHERE product_no NOT IN(SELECT product_no FROM
sales_order_details);

43. Findthe customer name, address1, address2, city and pincode for the client who has placed
order_no S00001?
SELECT name, address1,address2, city, state, pincode
FROM client_master
WHERE client_no IN(SELECT client_no FROM sales_order WHERE
s_order_no = 'S00001');

44.Find the client name who have placed orders before the month of may,13?
SELECT Client_no, name
FROM client_master
WHERE client_no IN(SELECT client_no FROM sales_order WHERE
TO_CHAR(S_ORDER_DATE, 'MON,YY') < 'MAY,13');

45.Find out if product ’Mouse’ is ordered by any client and print the client_no, name to whom it is
sold?
SELECT Client_no , Name FROM client_master WHERE client_no
IN(SELECT client_no FROM sales_order WHERE s_order_no IN(SELECT
s_order_no FROM sales_order_details WHERE Product_no IN(SELECT
product_no FROM product_master WHERE description = 'Mouse')));

46.Find the names of client who have placed orders Rs 10000 or more?
SELECT NAME FROM client_master
WHERE client_no IN(SELECT client_no FROM sales_order WHERE
s_order_no IN(SELECT s_order_no FROM sales_order_details
WHERE(qty_order * product_rate:: numeric) >= 10000));

S-ar putea să vă placă și