You are on page 1of 9

5/17/2017 DataWareHouse/ETLTESTING:SQLInterviewQuestionsandAnswersPart1

1 More NextBlog CreateBlog SignIn

DataWareHouse/ETL
TESTING
Sunday,26August2012

Followers
SQLInterviewQuestionsand Followers(23)Next

AnswersPart1

Q)ihaveemptableinwhichcolumnsareempid,empname,salnowiwantto
increasethesaloftheparticularempwhosesalis<10000with2000RS&sal
>10000&<20000with4000RSandwhosesalis>20000with5000RSnow
writeasingleupdatequery.

UPDATEEmp Follow
SETsal=sal+
CASE
WHENsal>=1000ANDsal<2000THEN200
WHENsal>=2000ANDsal<3000THEN300 BlogArchive
END
2012(47)
1. The following query retrieves "2" highest paid employees FROM August(43)
each Department :
WhatisDataWarehouse?

SELECT deptno, empno, sal DWHArchitecture


FROM emp e OperationalDataStore(ODS)
WHERE
whatisthedifferencebetween
2 > ( SELECT COUNT(e1.sal)
databasevsdatawar...
FROM emp e1
WHERE e.deptno = e1.deptno AND e.sal < e1.sal ) TypesofFactTablesinData
Warehouse
ORDER BY 1,3 DESC
TypesofSchemas
2. Query that will display the total no. of employees, and of that TestingStrategiesforData
total the number who were hired in 1980, 1981, 1982, and 1983. WarehouseApplications...
Give appropriate column headings. SQLInterviewQuestions

I am looking at the following output. We need to stick to this format. ETLTestingchallenges

DifferencebetweenDatabase
Total 1980 1981 1982 1983 andDataWarehouseTes...
ETLTestingProcess:

ETLTestingTechniques:
14 1 10 2 1
ETLorDatawarehouse
testing
SELECT COUNT (*), COUNT(DECODE(TO_CHAR (hiredate, UpdateStrategy
'YYYY'),'1980', empno)) "1980", Transformation

http://dwhtest.blogspot.in/2012/08/sqlinterviewquestionsandanswers.html 1/9
5/17/2017 DataWareHouse/ETLTESTING:SQLInterviewQuestionsandAnswersPart1

COUNT (DECODE (TO_CHAR (hiredate, 'YYYY'), Whatisdifferencebetween


'1981', empno)) "1981", JoinerandLookupTrans...
COUNT (DECODE (TO_CHAR (hiredate, 'YYYY'), SQLQueryOverwritein
'1982', empno)) "1982", SourceQulifier
COUNT (DECODE (TO_CHAR (hiredate, 'YYYY'),
WhatisDifferencebetween
'1983', empno)) "1983" RouterandFilterTrans...
FROM emp
SequenceGenerator
Transformation
3. Query for listing Deptno, ename, sal, SUM(sal in that dept) :
ExpressionTransformation

SELECT a.deptno, ename, sal, (SELECT SUM(sal) FROM emp b RankTransformation
WHERE a.deptno = b.deptno)
RouterTransformation
FROM emp a
ORDER BY a.deptno TransformationTips

FilterTransformation
OUTPUT :
AggregatorTransformation
=======
DEPTNO ENAME SAL SUM (SAL) JoinerTransformation
========= ======= ==== =========
UnionTransformation
10 KING 5000 11725
30 BLAKE 2850 10900 Whataretheactiveand
passivetransformations?
10 CLARK 2450 11725
10 JONES 2975 11725 TypesofTesting
30 MARTIN 1250 10900 TestCase
30 ALLEN 1600 10900
Bug/DefectLifeCycle
30 TURNER 1500 10900
30 JAMES 950 10900 DefectTrackingFormat
30 WARD 2750 10900
Vmodel
20 SMITH 8000 33000
20 SCOTT 3000 33000 TestDesignPlan
20 MILLER 20000 33000 SoftwareRequirements
Specification(SRS)
4. Create a matrix query to display the job, the salary for that job SQLInterviewQuestionsand
based on department number, and the total salary for that job for AnswersPart1
all departments, giving each column an appropriate heading.
SQLInterviewQuestionsand
Answerspart2
The output is as follows we need to stick to this format :
SQLInterviewQuestionsand
AnswersPart3
Job Dept 10 Dept
ETLTestinglifecycle
20 Dept 30 Total
SQLInterviewQuestionsand
AnswersPartt4
ANALYST SQLInterviewQuestionsand
6000 6000 AnswersPart5
CLERK 1300 SQLInterviewQuestionsand
1900 950 4150 AnswersPart6
MANAGER 2450
SQLInterviewQuestionsand
2975 2850 8275 AnswersPart7
PRESIDENT
SQLInterviewQuestionsand
5000
AnswersPart8
5000
SALESMAN September(4)
5600 5600

AboutMe
http://dwhtest.blogspot.in/2012/08/sqlinterviewquestionsandanswers.html 2/9
5/17/2017 DataWareHouse/ETLTESTING:SQLInterviewQuestionsandAnswersPart1

SELECT job "Job", SUM (DECODE (deptno, 10, sal)) "Dept 10", leelabattu
SUM (DECODE (deptno, 20, sal)) "Dept 20", Follow 2

SUM (DECODE (deptno, 30, sal)) "Dept 30",


Viewmycompleteprofile
SUM (sal) "Total"
FROM emp
GROUP BY job

5. 4thTop Salary of all the employees:

SELECT DEPTNO, ENAME, SAL


FROM EMP A
WHERE
3 = (SELECT COUNT(B.SAL) FROM EMP B
WHERE A.SAL < B.SAL) ORDER BY SAL DESC

6. Retrieving the 5th row FROM a table:

SELECT DEPTNO, ENAME, SAL


FROM EMP
WHERE ROWID = (SELECT ROWID FROM EMP WHERE ROWNUM <=
5
MINUS
SELECT ROWID FROM EMP WHERE ROWNUM < 5)

7. Tree Query :

Name Null? Type



SUB NOT NULL VARCHAR2(4)
SUPER VARCHAR2(4)
PRICE NUMBER(6,2)

SELECT sub, super


FROM parts
CONNECT BY PRIOR sub = super
START WITH sub = 'p1'

8. Eliminate duplicates rows in a table :

DELETE FROM table_name A


WHERE ROWID > ( SELECT min(ROWID) FROM table_name B
WHERE A.col = B.col)

9. Displaying EVERY 4th row in a table : (If a table has 14 rows,


4,8,12 rows will be selected)

SELECT *
FROM emp
WHERE (ROWID,0) IN (SELECT ROWID, MOD(ROWNUM,4)
FROM emp)
10. Top N rows FROM a table : (Displays top 9 salaried people)

SELECT ename, deptno, sal


FROM (SELECT * FROM emp ORDER BY sal DESC)

http://dwhtest.blogspot.in/2012/08/sqlinterviewquestionsandanswers.html 3/9
5/17/2017 DataWareHouse/ETLTESTING:SQLInterviewQuestionsandAnswersPart1

WHERE ROWNUM < 10

11. How does one count/sum RANGES of data values in a column?


A value x will be between values y and z if GREATEST(x, y) =
LEAST(x, z).

SELECT
f2,
COUNT(DECODE(greatest(f1,59), least(f1,100), 1, 0)) "Range
60100",
COUNT(DECODE(greatest(f1,30), least(f1, 59), 1, 0)) "Range
3059",
COUNT(DECODE(greatest(f1,29), least(f1, 0), 1, 0)) "Range
0029"
FROM my_table
GROUP BY f2

12. For equal size ranges it migth be easier to calculate it with


DECODE(TRUNC(value/range), 0, rate_0, 1, rate_1, ...).

SELECT ename "Name", sal "Salary",


DECODE( TRUNC(sal/1000, 0), 0, 0.0,
1, 0.1,
2, 0.2,
3, 0.3) "Tax rate"
FROM emp

13. How does one count different data values in a column?

COL NAME DATATYPE



DNO NUMBER
SEX CHAR

SELECT dno, SUM(DECODE(sex,'M',1,0)) MALE,


SUM(DECODE(sex,'F',1,0)) FEMALE,
COUNT(DECODE(sex,'M',1,'F',1)) TOTAL
FROM t1
GROUP BY dno

14. Query to get the product of all the values of a column :

SELECT EXP(SUM(LN(col1))) FROM srinu

15. Query to display only the duplicate records in a table:

SELECT num
FROM satyam
GROUP BY num
HAVING COUNT(*) > 1

16. Query for getting the following output as many number of rows
in the table :

http://dwhtest.blogspot.in/2012/08/sqlinterviewquestionsandanswers.html 4/9
5/17/2017 DataWareHouse/ETLTESTING:SQLInterviewQuestionsandAnswersPart1

**
***
****
*****

SELECT RPAD(DECODE(temp,temp,'*'),ROWNUM,'*')
FROM srinu1

17. Function for getting the Balance Value :

FUNCTION F_BALANCE_VALUE
(p_business_group_id number, p_payroll_action_id number,
p_balance_name varchar2, p_dimension_name varchar2) RETURN
NUMBER
IS
l_bal number
l_defined_bal_id number
l_assignment_action_id number
BEGIN
SELECT assignment_action_id
INTO l_assignment_action_id
FROM
pay_assignment_actions
WHERE
assignment_id = :p_assignment_id
AND payroll_action_id = p_payroll_action_id

SELECT
defined_balance_id
INTO
l_defined_bal_id
FROM
pay_balance_types pbt,
pay_defined_balances pdb,
pay_balance_dimensions pbd
WHERE
pbt.business_group_id = p_business_group_id
AND UPPER(pbt.balance_name) = UPPER(p_balance_name)
AND pbt.business_group_id = pdb.business_group_id
AND pbt.balance_type_id = pdb.balance_type_id
AND UPPER(pbd.dimension_name) =
UPPER(p_dimension_name)
AND pdb.balance_dimension_id = pbd.balance_dimension_id

l_bal :=
pay_balance_pkg.get_value(l_defined_bal_id,l_assignment_action_id)

RETURN (l_bal)

exception
WHEN no_data_found THEN
RETURN 0
END

18. Function for getting the Element Value :

http://dwhtest.blogspot.in/2012/08/sqlinterviewquestionsandanswers.html 5/9
5/17/2017 DataWareHouse/ETLTESTING:SQLInterviewQuestionsandAnswersPart1

FUNCTION f_element_value(
p_classification_name in varchar2,
p_element_name in varchar2,
p_business_group_id in number,
p_input_value_name in varchar2,
p_payroll_action_id in number,
p_assignment_id in number
)
RETURN number
IS
l_element_value number(14,2) default 0
l_input_value_id pay_input_values_f.input_value_id%type
l_element_type_id pay_element_types_f.element_type_id%type
BEGIN
SELECT DISTINCT element_type_id
INTO l_element_type_id
FROM pay_element_types_f pet,
pay_element_classifications pec
WHERE pet.classification_id = pec.classification_id
AND upper(classification_name) =
upper(p_classification_name)
AND upper(element_name) =
upper(p_element_name)
AND pet.business_group_id = p_business_group_id

SELECT input_value_id
INTO l_input_value_id
FROM pay_input_values_f
WHERE upper(name) = upper(p_input_value_name)
AND element_type_id = l_element_type_id

SELECT NVL(prrv.result_value,0)
INTO l_element_value
FROM pay_run_result_values prrv,
pay_run_results prr,
pay_assignment_actions paa
WHERE prrv.run_result_id = prr.run_result_id
AND prr.assignment_ACTION_ID = paa.assignment_action_id
AND paa.assignment_id = p_assignment_id
AND input_value_id = l_input_value_id
AND paa.payroll_action_id = p_payroll_action_id

RETURN (l_element_value)

exception
WHEN no_data_found THEN
RETURN 0
END

19. SELECT Query for counting No of words :

SELECT ename,
NVL(LENGTH(REPLACE(TRANSLATE(UPPER(RTRIM(ename)),'ABCDEF
GHIJKLMNOPQRSTUVWXYZ'' ',' @'),' ',''))+1,1)
word_length
FROM emp
http://dwhtest.blogspot.in/2012/08/sqlinterviewquestionsandanswers.html 6/9
5/17/2017 DataWareHouse/ETLTESTING:SQLInterviewQuestionsandAnswersPart1

Explanation :

TRANSLATE(UPPER(RTRIM(ename)),'ABCDEFGHIJKLMNOPQRSTUVW
XYZ'' ',' @') This will translate all the characters
FROM AZ including a single quote to a space. It will also translate a
space to a @.

REPLACE(TRANSLATE(UPPER(RTRIM(ename)),'ABCDEFGHIJKLMNOP
QRSTUVWXYZ'' ',' @'),' ','') This will replace every
space with nothing in the above result.

LENGTH(REPLACE(TRANSLATE(UPPER(RTRIM(ename)),'ABCDEFGHIJ
KLMNOPQRSTUVWXYZ'' ',' @'),' ',''))+1 This will give
u the count of @ characters in the above result.

20. Function to check for a leap year :

CREATE OR REPLACE FUNCTION is_leap_year (p_date IN DATE)


RETURN VARCHAR2
AS
v_test DATE
BEGIN
v_test := TO_DATE ('29Feb' || TO_CHAR
(p_date,'YYYY'),'DDMonYYYY')
RETURN 'Y'
EXCEPTION
WHEN OTHERS THEN
RETURN 'N'
END is_leap_year

SQL> SELECT hiredate, TO_CHAR (hiredate, 'Day') weekday


FROM emp
WHERE is_leap_year (hiredate) = 'Y'

Postedbyleelabattuat10:28:00pm
+1 Recommend this on Google

Labels:SQL

7comments:
TekClasses 21September2015at15:48
Thiswasreallyagoodpostandalsoveryinformative.formoredetails

http://www.tekclasses.com/
Reply

TekClasses 21September2015at16:04
Infoisverygood..Veryinformativearticlepost.formoredetails

http://www.tekclasses.com/
Reply
http://dwhtest.blogspot.in/2012/08/sqlinterviewquestionsandanswers.html 7/9
5/17/2017 DataWareHouse/ETLTESTING:SQLInterviewQuestionsandAnswersPart1
Reply

TekClasses 21September2015at16:28
Yourblogisreallyuseful.Thanksforsharingthisuseful
blog..Supposeifanyoneinterestedtolearn

http://www.tekclasses.com/
Reply

Interviewquestionsanswerspdf 10June2016at17:16
DataWarehousingInterviewQuestionsandAnswers
http://allinterviewquestionsandanswerspdf.blogspot.in/2016/06/top100
datawarehousinginterview.html
Reply

PradeepReddy 12September2016at15:35
Very good collection of question and answers thank you for sharing this
article.KnowmoreaboutETLTestingTraining
Reply

PradeepReddy 12September2016at15:35
Very good collection of question and answers thank you for sharing this
article.KnowmoreaboutETLTestingTraining
Reply

EmergersTechnologies 21April2017at17:18
Just found your post by searching on the Google, I am Impressed and
LearnedLotofnewthingfromyourpost.Iamnewtobloggingandalways
try to learn new skill as I believe that blogging is the full time job for
learningnewthingsdaybyday.
"EmergersTechnologies"
Reply

Enteryourcomment...

Commentas: Unknown(Google) Signout


Publish Preview Notifyme

http://dwhtest.blogspot.in/2012/08/sqlinterviewquestionsandanswers.html 8/9
5/17/2017 DataWareHouse/ETLTESTING:SQLInterviewQuestionsandAnswersPart1

NewerPost Home OlderPost

Subscribeto:PostComments(Atom)

TotalPageviews

59,595

SearchThisBlog
Search

sri.Watermarktheme.PoweredbyBlogger.

http://dwhtest.blogspot.in/2012/08/sqlinterviewquestionsandanswers.html 9/9

You might also like