Dbms Exp4
Dbms Exp4
9629
Related Course outcome : At the end of the course, Students will be able to Use
SQL : Standard language of relational database
Knowledge Unable to
Unable to answer 1 Able to answer
In depth knowledge of the answer 2
question (1) 2 questions (2)
QUERY assignment(2) questions(0)
Assessment Marks :
Timeliness (3)
Completeness and
neatness (3)
Originality(2)
Knowledge (2)
Total (10)
Teacher's Sign :
Tools PostgreSQL/MySql
Theory SELECT: SELECT statement returns a result set of records from one or more tables.
The select statement has optional clauses:
WHERE specifies which rows to retrieve
GROUP BY groups rows sharing a property so that an aggregate function can
be applied to each group having group.
HAVING selects among the groups defined by the GROUP BY clause.
ORDER BY specifies an order in which to return the rows.
Syntax:
SELECT<attribute list>
FROM<table list>
WHERE<condition>
Where
TASK 1:
Procedure 1. Create following table: Data type Size Constraint
Table name : sales_order
Column
Name
NOT
Order_date date
NULL
NOT
Client_no varchar 6
NULL
Dely_addr varchar 25
Salesman_no varchar 6
Dely_type char 1
Billed_yn char 1
Dely_date Date
Order_status varchar 10
SOLUTIONS:
1. Create following table: Table
name : sales_order
CREATE TABLE sales_order_9629(
order_no varchar(6) Primary key,
order_date date NOT NULL,
Client_no varchar(6) NOT NULL,
Dely_addr varchar(25),
Salesman_no varchar(6),
Dely_type char(5),
Billed_yn char(1),
Dely_date date,
Order_status varchar(10)
);
CREATE TABLE
client_master_9629( client_no varchar(6),
client_name varchar(20), address
varchar(30), city varchar(15), pincode
numeric(8), state1 varchar(15), due_bal
numeric(10,2)
);
CREATE TABLE
product_master_9629( product_no
varchar(6), description varchar(15),
profit_percent numeric(4,2), unit_measure
varchar(10), qty_on_hand varchar(8),
reorder_level numeric(8), sell_price
numeric(8,2), cost_price numeric(8,2)
);
2. Insert 5-6 records in table.
INSERT INTO client_master_9629 VALUES('C001','Sam','Kothrud','Pune',411077,'Maharashtra',10000.23);
INSERT INTO client_master_9629 VALUES('C002','John','Kurla','Mumbai',400087,'Maharashtra',50000.55); INSERT INTO
client_master_9629 VALUES('C003','Jack','Kishan Nagar','Gandhinagar',400055,'Gujarat',25000.93);
INSERT INTO client_master_9629 VALUES('C004','Ann','Charminar','Hydrabad',400090,'Andhra Pradesh',77000.00);
INSERT INTO client_master_9629 VALUES('C005','Peter','Bandra','Mumbai',400045,'Maharashtra',88000.23);
INSERT INTO client_master_9629 VALUES('C006','Nick','Vasai','Mumbai',400077,'Maharashtra',10000.23);
3. Find the names of all clients having ‘a’ as the second letter in their names.
4. Find out the clients who stay in a city whose second letter is ‘a’
5. Find the list of all clients who stay in ‘mumbai’ ordered by their names
7. Print the information from sales_order table for orders placed in themonth of January
9. Find the products whose selling price is greater than 2000 and less than orequal to 5000
SELECT * FROM product_master_9629 WHERE sell_price > 2000 AND sell_price <= 5000;
10. Find the products whose selling price is more than 1500. Calculate newselling price as
original selling price * 1.5. Rename the new column in the above query as new_price
SELECT product_no, sell_price * 1.5 AS new_price FROM product_master_9629 WHERE sell_price > 1500;
14.Count the number of products having price greater than or equal to 1500
15. Display the order number and day on which clients placed their order
19. Find the no. of days elapsed between today’s date and the delivery dateof orders placed
by the clients.