0% found this document useful (0 votes)
37 views8 pages

Class Xii Ip Practical File 2020 21

Uploaded by

rajputaanya613
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)
37 views8 pages

Class Xii Ip Practical File 2020 21

Uploaded by

rajputaanya613
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/ 8

Database query using SQL (Mathematical, string,

Date and time functions in SQL)

Consider table SALESMAN with following data:


SNO SNAME SALARY BONUS DATEOFJOIN
A01 Beena Mehta 30000 45.23 2019-10-29
A02 K. L. Sahay 50000 25.34 2018-03-13
B03 Nisha Thakkar 30000 35.00 2017-03-18
B04 Leela Yadav 80000 NULL 2018-12-31
C05 Gautam Gola 20000 NULL 1989-01-23
C06 Trapti Garg 70000 12.37 1987-06-15
D07 Neena Sharma 50000 27.89 1999-03-18

1) Display Salesman name , bonus after rounding off to zero decimal places.
Select SNAME, round(BONUS,0) from SALESMAN;

2) Display name, total salary of all salesman after addition of salary and
bonus and truncate it to 1 decimal places.
Select sname, truncate((SALARY+BONUS),1) from SALESMAN;
3
Page
3) Display remainder of salary and bonus of Salesman whose SNO starting
with ‘A’
Select MOD(SALARY,BONUS) from SALESMAN where SNO like ’A%’;

4) Display position of occurrence of string “ta” in salesmen name.


Select sname, instr(Sname,”ta”) from SALESMAN;

5) Display four characters from salesman name starting from second


character.
Select sname, substr(Sname,2,4) from SALESMAN;

4
Page
6) Display last 5 characters of name of SALESMAN.
Select sname, right(Sname,5) from SALESMAN;

7) Display details of salesman whose name containing 10 characters.


Select * from salesman where length(sname)=10;

8) Display month name for the date of join of salesman


Select DATEOFJOIN, monthname(DATEOFJOIN) from SALESMAN;

9) Display currentdate and day of the year of current date.


Select date (now()),dayofyear(date(now())) from dual;
5
Page
10) Display name of the weekday for the DATEOFJOIN of SALESMAN;
Select DATEOFJOIN,dayname(DATEOFJOIN) from SALESMAN;

11) Display SNO, name of the youngest SALESMAN.


Select sno, sname, dateofjoin from salesman where dateofjoin=(select
max(DATEOFJOIN) from SALESMAN);

12) Display name and salary of the oldest SALESMAN.


Select sname, salary, dateofjoin from salesman where dateofjoin=(select
min(dateofjoin) from salesman);

6
Page
Database query using SQL (Aggregate functions ,Group
by ,order by query in SQL)

Consider the following table Vehicle:


V_no Type Company Price Qty
AW125 Wagon Maruti 250000 25
J00083 Jeep Mahindra 4000000 15
S9090 SUV Mistubishi 2500000 18
M0892 Mini Van Datsun 1500000 26
W9760 SUV Maruti 2500000 18
R2409 Mini Van Mahindra 350000 15

1. Display the average price of each type of vehicle having quantity more than
20.
Select Type, avg(price) from vehicle where qty>20 group by Type;

2. Count the type of vehicles manufactured by each company.


Select Company, count(distinct Type) from Vehicle group by Company;

7
Page
3. Display total price of all types of vehicle.
Select Type, sum(Price* Qty) from Vehicle group by Type;

4. Display the details of the vehichle having maximum price.


Select * from vehicle where price=(select max(price) from vehicle);

5. Display total vehicles of Maruti company.


Select company,sum(qty) from vehicle
group by company
having company='Maruti';
8
Page
6. Display average price of all type of vehicles.
Select type,avg(price) from vehicle group by type;

7. Display type and minimum price of each vehicle company.


Select type,company,min(price) from vehicle group by company;

8. Display minimum, maximum, total and average price of Mahindra


company vehicles.
Select company, min(price),max(price),sum(price),avg(price) from vehicle where
company='Mahindra';
9
Page
9. Display details of all vehicles in ascending order of their price.
Select * from vehicle order by price asc;

10.Display details of all vehicles in ascending order of type and descending


order of vehicle number.
Select * from vehicle order by type asc,v_no desc;

10
Page

You might also like