SQL Queries on the Database
Insert the following information:
Table: Item
Itemno Iname Price Quantity
101 Soap 50 100
1.
102 Powder 100 50
103 Face cream 150 25
104 Pen 50 200
105 Soap box 20 100
Write queries based upon Item table given in q. no 1.
a) Display all items information.
b) Display item name and price value.
c) Display soap information.
d) Display the item information whose name starts with letter 's'.
e) Display a report with item number, item name and total price.
(total price = price * quantity).
2.
f) Display item table information in ascending order based upon
item name.
g) Display item name and price in descending order based upon
price.
h) Display item name, whose price is in between 50 to 100.
i) Add new column totalprice with number (10, 2).
j) Increase price value by 100.
k) Fill up totalprice = price * quantity.
l) Remove powder information.
m) Remove totalprice column.
n) Remove whole item structure.
Write outputs based upon Item table given in q. no 1.
a) select sum(price) from item;
b) select avg(price) from item;
c) select min(price) from item;
3. d) select max(price) from item;
e) select count(price) from item;
f) select distinct price from item;
g) select count(distinct price) from item;
h) select iname, price*quantity from item;
In a database there are two tables - 'Brand' and 'Item' as shown
below:
BRAND:
ICODE BNAME
100 SONY
200 HP
4.
300 LG
400 SAMSUNG
ITEM:
ICODE INAME PRICE
100 TELEVISION 25000
200 COMPUTER 30000
300 REFRIGERATOR 23000
400 CELL PHONE 40000
Write SQL queries for the following:
a) To display Iname, price and corresponding Brand name (Bname)
of those items, whose price is between 25000 and 30000 both
values inclusive).
b) To display ICode, Price and BName of the item, which has
IName as "Television".
c) To increase the Prices of all items by Rs. 10%.
Create the following table
Students
Column name Data type Size Constraints
Adno Integer 3 Primary key
Name Varchar 20
Average Integer 3
Sex Char 1
5. Scode Integer 4
Insert the following information:
Students
Adno Name Average Sex Scode
501 R.Jain 98 M 111
545 Kavita 73 F 333
705 K.Rashika 85 F 111
754 Rahul Goel 60 M 444
892 Sahil Jain 78 M 333
935 Rohan Saini 85 M 222
955 Anjali 64 F 444
983 Sneha 80 F 222
Aggarwal
Write queries based upon item table given in q. no 5.
(i) Display all students' information.
(ii) Display Rohan Saini's information.
(iii) Display number of students in the table.
(iv) Display number of students in each sex.
(v) Display students' information in ascending order using name.
(vi) Display students' information in descending order using
6. average marks.
(vii) Display students' name starting with letter "K".
(viii) Display students' information, whose name ends with "l".
(ix) Display a report with adno,name,average*5 as total marks from
student table.
(x) Display students' information, whose average marks are in
between 80 to 90.
(xi) Display students' info., who are getting average marks of more
than 80 and scode 333.
(xii) Display students' name and average marks, whose scode is 222
and 333.
(xiii) Display sum of average marks.
(xiv) Display maximum average marks
(xv) Display minimum average marks.
(xvi) Display average value of average marks.
(xvii) Display maximum, minimum and sum of average marks in
each scode.
(xviii) Display number of students in each scode.
Create the following table.
Column name Data type Size Constraints
Scode Integer 3 Primary key
Sname Varchar 20
Place Varchar 10
Insert the following information.
7.
Streams
Scode Sname Place
111 Science SBlock
222 Commerce CBlock
333 Humanity HBlock
444 Art ABlock
8. Write queries based upon item table given in q. no 5 & 7
(i) To display Adno, Name, Sex and Average from Student's table
and Stream name (Sname) and place from Stream table with respect
to Scode.
(ii) Add the following information into the student table.
999 Deepak Sharma 83 M 2222
(iii) Display science stream students' information.