SQL QUERY
1. Retrieve specified information for the account holder who are not in
‘Ahmedabad’.
Ans:
select * from account where city not in ‘Ahemdabad’;
2. Retrieve specified information for the account holder who are not in
‘Ahmedabad or ‘Vadodara’.
Ans: select * from account where city not in('Ahemadabad', 'Vadodara');
3. Retrieve those records of Account holder whose balance between is
50000 and 100000.
Ans:
select * from account where balance between 50000 and 1000000;
.4.Retrieve those records of Account holder whose balance not between is
50000 and 100000.
Ans:
select * from account where balance not between 50000 and 100000;
5. Display only those records whose amount is 5000, 25000, 30000.
Ans:
select * from Transaction where amount in (5000, 25000, 30000);
6. Display only those records whose amount not in 5000, 25000, 30000.
Ans: select * from Transaction where Amt not in
(5000, 25000, 30000);
7.Display
System date.
Ans:
select sysdate from dual;
8. Find the
date,15 days after today’s date.
Ans: select sysdate + 15 from dual;
9.. Perform the following operation using a DUAL table.
5*5,34+34,1000/300,length of
‘uvpce’,display only month of systemdate
1: select 5*5 "multiplication" from
dual;
2: select 34+34 "sum"
from dual;
3:select 1000/300 "Div"
from dual;
4:select length('uvpce')
"Length" from dual;
5:selectto_char(sysdate, ‘mon’)
from dual;
10.Find the date,20 days before today’s date.
Ans: select sysdate - 20 from dual;
Transaction:
1.create
table Transaction(Acc_no varchar2(5), tr_Date Date, Amt Number(10,2), type_of_tr Char(1), mode_of_pay
varchar2(10));
insert
into Transaction values('A001', '03-may-04', 10000, 'D', 'cash');
insert
into Transaction values('A002', '05-july-04', 5000, 'W', 'Cheque');
insert
into Transaction values('A003', '12-Aug-04', 25000, 'D', 'Cheque');
insert
into Transaction values('A004', '15-may-04', 30000, 'D', 'Cheque ');
insert
into Transaction values('A005', '22-oct-04', 15000, 'W', 'cash');
1.Find the total transaction amount of account holder from transaction
table.
Ans:
select sum(amt)”sum” from Transaction;
2.Find minimum amount of transaction.
Ans:
select min(amt)”min” from Transaction;
3.Find maximum amount of transaction.
Ans:
select max(amt)”max” from Transaction;
4.Count the total account holders.
Ans:
select count(acc_no)”acc_hoder” from Transaction;
5.Count only those records whose made of payment is ‘cash’.
Ans:
select count(acc_no)”cash” from
Transaction where mode_of_pay = 'cash';
6.Count only those records whose transaction made in the month of ‘MAY’.
Ans:
select count(Acc_no)”may” from
Transaction where to_char(tr_date, 'mon') = 'may';
7.Find the average value of transaction.
Ans:
select avg(amt)”avg” from Transaction;
8.Display the result of 4 rest to 4.
Ans:
select power(4, 4) from dual;
9.Find the square root of 25.
Ans:
select sqrt(25) from dual;
10.Write the query for the following Function.
Ans:
1:select lower('UVPCE') from
dual;
2:select upper('uvpce') from
dual;
3:selectinitcap('uvpce') from
dual;
4:selectsubstr('uvpce',2, 3) from
dual;
5:select length ('uvpce') from
dual;
6:selectLtrim('uvpce', 'u') from
dual;
7:selectrtrim('uvpce', 'e') from
dual;
8:selectlpad('uvpce', 10, '#')
from dual;
9:selectrpad('uvpce', 10 ,
'&') from dual;
Comments
Post a Comment