0% found this document useful (0 votes)
9 views

Dbms Exp6 Solution

The document creates tables to store sales order details, customer details, and order-customer mappings. It then inserts sample records and writes queries to retrieve summary data like total quantity sold by product or total billed amount for a month.

Uploaded by

Nishant Patil
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)
9 views

Dbms Exp6 Solution

The document creates tables to store sales order details, customer details, and order-customer mappings. It then inserts sample records and writes queries to retrieve summary data like total quantity sold by product or total billed amount for a month.

Uploaded by

Nishant Patil
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/ 4

Exp6

1.Create following table:

Table name : sales_order_details

CREATE TABLE sales_order_details (order_no varchar(6) PRIMARY KEY, product_no varchar(6),


qty_ordered numeric(8), qty_disp numeric(8), product_rate numeric(10,2), order_date date);

Create table- customer(cid, cname, address, pno)

CREATE TABLE customer (cid numeric PRIMARY KEY, cname varchar, address varchar, pno varchar);

Create table- cust_order(cid foreign key, order_no foreign key)

CREATE TABLE cust_order (cid numeric REFERENCES customer(cid), order_no varchar REFERENCES
sales_order_details(order_no));

2.Insert 5-6 records in table in each tables.

insert into sales_order_details values ('C01','P01',15,7,1525.50,'01-01-2023');


insert into sales_order_details values ('C02','P02',10,3,1000.50,'24-02-2023');
insert into sales_order_details values ('C03','P03',12,10,1200.75,'10-12-2022');
insert into sales_order_details values ('C04','P04',25,18,2000.50,'18-01-2023');
insert into sales_order_details values ('C05','P05',15,10,1525.50,'06-01-2023');
insert into sales_order_details values ('C06','P06',5,2,500.00,'12-12-2022');

insert into customer values (01,'James','US','P01');


insert into customer values (02,'Smith','US','P02');
insert into customer values (03,'Ann','UK','P03');
insert into customer values (04,'Jack','Australia','P04');
insert into customer values (05,'Ryan','Australia','P05');
insert into customer values (06,'John','UK','P06');
insert into cust_order values (01,'C01');
insert into cust_order values (02,'C02');
insert into cust_order values (03,'C03');
insert into cust_order values (04,'C04');
insert into cust_order values (05,'C05');
insert into cust_order values (06,'C06');

3.Print the description and total qty sold for each product

select order_no,product_no,qty_disp from sales_order_details;

4.Find the value of each product sold

select qty_disp*product_rate as total_value from sales_order_details;


5.Calculate the average quantity sold for each client that has a maximum order value of 15000

select avg(qty_disp) as avg_qty_sold from sales_order_details where product_rate*qty_ordered<=


15000;

6.Find out the sum total of all the billed orders for the month of January

select sum(product_rate*qty_ordered) AS total_sum from sales_order_details where


to_char(order_date,'MON')='JAN';

7.Find out the name of customers who have given the order of more than 10 qty

select c.cname

from customer c

inner join cust_order co on c.cid = co.cid

inner join sales_order_details sod on co.order_no = sod.order_no

where sod.qty_ordered > 10;


8.Find out the customer names with product no with maximum qty ordered.

select c.cname, sod.product_no

from customer c

inner join cust_order co on c.cid = co.cid

inner join sales_order_details sod on co.order_no = sod.order_no

where sod.qty_ordered = (select MAX(qty_ordered) from sales_order_details);

You might also like