Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
40 views

12 IP SQL Queries File-1-2

The document discusses SQL queries on sample tables containing transaction and employee data. It provides SQL queries to retrieve specific data from the tables along with expected outputs. Sample queries include selecting transaction types, employee details by joining tables, and aggregation functions to analyze the data.

Uploaded by

abesaale10
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

12 IP SQL Queries File-1-2

The document discusses SQL queries on sample tables containing transaction and employee data. It provides SQL queries to retrieve specific data from the tables along with expected outputs. Sample queries include selecting transaction types, employee details by joining tables, and aggregation functions to analyze the data.

Uploaded by

abesaale10
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL QUERY (Practical File) for more details visit : python4csip.

com

1 Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii) which are based on tables

TABLE: TRANSACT
TRNO ANO AMOUNT TYPE DOT
T001 101 2500 Withdraw 2017-12-21
T002 103 3000 Deposit 2017-06-01
T003 102 2000 Withdraw 2017-05-12
T004 103 1000 Deposit 2017-10-22
T005 102 12000 Deposit 2017-11-06

(i) To display details of all transactions of TYPE Withdraw from TRANSACT table
(ii) To display ANO and AMOUNT of all Deposit and Withdrawals done in month of
„May‟ 2017 from table TRANSACT
(iii) To display first date of transaction (DOT) from table TRANSACT for Account having
ANO as 102
(iv) To display ANO, ANAME, AMOUNT and DOT of those persons from ACCOUNT and
TRANSACT table who have done transaction less than or equal to 3000
(v) SELECT ANO, ANAME FROM ACCOUNT
WHERE ADDRESS NOT IN ('CHENNAI', 'BANGALORE');
(vi) SELECT DISTINCT ANO FROM TRANSACT
(vii) SELECT ANO, COUNT(*), MIN(AMOUNT) FROM TRANSACT
GROUP BY ANO HAVING COUNT(*)> 1
(viii) SELECT COUNT(*), SUM(AMOUNT) FROM TRANSACT
WHERE DOT <= '2017-10-01'
Ans. (i) Select * from TRANSACT where TYPE=’Withdraw’;
(ii) Select ANO, AMOUNT from TRANSACT where DOT like ‘%-05-%’;
(iii) Select MIN(DOT) from TRANSACT where ANO=102
(iv) Select ANO,T.ANO,ANAME,AMOUNT from ACCOUNT A, TRANSACT T where A.ANO = T.ANO and
AMOUNT<=3000;
(v)
ANO ANAME
-------------------------------------
103 Ali Reza
105 Simran Kaur
(vi)
ANO
----------
101
103
102
(vii)

(viii)

Page :4
for more details visit : python4csip.com

2 Consider the following tables EMP and SALGRADE, write the query for (i) to (vi) and output
for (vii) to (x)
TABLE: EMPLOYEE
ECODE NAME DESIG SGRADE DOJ DOB
101 Vikrant Executive S03 2003-03-23 1980-01-13
102 Ravi Head-IT S02 2010-02-12 1987-07-22
103 John Cena Receptionist S03 2009-06-24 1983-02-24
105 Azhar Ansari GM S02 2009-08-11 1984-03-03
108 Priyam Sen CEO S01 2004-12-29 1982-01-19
TABLE: SALGRADE
SGRADE SALARY HRA
S01 56000 18000
S02 32000 12000
S03 24000 8000
(i) To display details of all employee in descending order of their DOJ
(ii) To display NAME AND DESIG of those employees whose sgrade is either „S02‟ or
„S03‟
(iii) To display NAME, DESIG, SGRADE of those employee who joined in the year 2009
(iv) To display all SGRADE, ANNUAL_SALARY from table SALGRADE [where
ANNUAL_SALARY = SALARY*12]
(v) To display number of employee working in each SALGRADE from table EMPLOYEE
(vi) To display NAME, DESIG, SALARY, HRA from tables EMPLOYEE and SALGRADE
where SALARY is less than 50000
(vii) Select MIN(DOJ), MAX(DOB) from employee;
(viii) Select SGrade,Salary+HRA from SalGrade where Sgrade=‟S02‟
(ix) Select count(distinct sgrade) from employee
(x) Select sum(salary), avg(salary) from salgrade
Ans (i) SELECT * FROM EMPLOYEE ORDER BY DOJ DESC
(ii) SELECT NAME,DESIG FROM EMPLOYEE WHERE SGRADE IN ('S02','S03')
OR
SELECT NAME,DESIG FROM EMPLOYEE WHERE SGRADE='S02' OR
SGRADE='S03'
(iii) SELECT NAME,DESIG,SGRADE FROM EMPLOYEE WHERE DOJ LIKE '2009%'
(iv) SELECT SGRADE,SALARY*12 ANNUAL_SALARY FROM SALGRADE
(v) SELECT SGRADE,COUNT(*) FROM EMPLOYEE GROUP BY SGRADE
(vi) SELECT NAME,DESIG,SALARY,HRA FROM EMPLOYEE E,SALGRADE S WHERE
E.SGRADE=S.SGRADE AND SALARY<=50000
(vii) MIN(DOJ) MAX(DOB)
------------------------------------
2003-03-23 1987-07-22
(viii) SGRADE SALARY+HRA
---------------------------------
S02 44000
(ix) COUNT(*)
---------------
3
(x) SUM(SALARY) AVG(SALARY)
--------------------------------------------
112000 37333.33

Page :5

You might also like