EXL asked questions covering Python and SQL in a recent interview. These on SQL Joins, Rank functions, and Python Lists and functions.

Table of contents
SQL interview questions
Here are two tables. Table_a and Table_b with data below.
Table_a
id
--
1
1
1
1
null
Table_b
id
--
1
1
1
Q.1 Count the output rows for INNER JOIN, LEFT JOIN, FULL JOIN, and RIGHT JOIN?
INNER JOIN
12
LEFT JOIN
13
FULL JOIN
13
RIGHT JOIN
12
Q.2 Add new columns (rank(), dense_rank(), row_number()) in the output of the emp table?
Here, in each query, the rank function has been changed.
SELECT empno, ename, job, mgr, hiredate, sal, comm, deptno,
RANK() OVER (PARTITION BY hiredate ORDER BY sal) AS salrank
FROM emp
ORDER BY sal;
SELECT empno, ename, job, mgr, hiredate, sal, comm, deptno,
DENSE_RANK() OVER (PARTITION BY hiredate ORDER BY sal) AS salrank
FROM emp
ORDER BY sal;
SELECT empno, ename, job, mgr, hiredate, sal, comm, deptno,
ROW_NUMBER() OVER (PARTITION BY hiredate ORDER BY sal) AS salrank
FROM emp
ORDER BY sal;
Q.3 Find employees in each dept where the count of employees is > 2?
SELECT DEPTNO, COUNT(EMPNO) as COUNT_OF_EMP
FROM EMP
GROUP BY DEPTNO
HAVING COUNT(EMPNO) > 2;
Output
DEPTNO COUNT_OF_EMP
30 6
10 3
20 5
Python interview questions
Q.1 Write a method to calculate Squares and Cubes for the given number. Show only Cubes in the output?
#function
def calc(numb):
sq = numb ** 2
cu = numb **3
return sq, cu
#calling function
squares, cubes = calc(10)
print(cubes)
Output
------
1000
** Process exited - Return Code: 0 **
Press Enter to exit terminal
Q.2 Check each element in a list. If the number is < 100 write to a new list?
a = [ 200, 300, 50, 10, 160]
output = []
for i in a:
if i > 100:
output.append(i)
print(output)
Result
-------
[200, 300, 160]
** Process exited - Return Code: 0 **
Press Enter to exit terminal
Q.3 Check each element in a list. If it is an integer, continue the loop, else, break the loop?
Method-1
=========
a = [1000, 2000, 3000, "NA"]
x = all(isinstance(i, int) for i in a)
if x:
# Continue with your code here
pass
else:
# Break out of the loop or handle the case where not all elements are integers
print(" all the elements are not int")
Method-2
========
a = [1000, 2000, 3000, "NA"]
for i in a:
if isinstance(i, int):
pass
else:
print("All the elements not the int")
break







You must be logged in to post a comment.