SQL Query Interview Questions - Part 5
SQL Query Interview Questions - Part 5
Home Data Warehouse Informatica Informatica Scenarios Informatica Cloud Oracle Unix Hadoop
Search... Search
SQL Query Interview Questions - Part 5
Write SQL queries for the below interview questions:
Popular Posts
(
Top Examples of Awk Command in Unix
PRODUCT_ID INTEGER,
PRODUCT_NAME VARCHAR2(30) Sed Command in Unix and Linux Examples
);
Design/Implement/Create SCD Type 2 Effective Date
Mapping in Informatica
INSERT INTO PRODUCTS VALUES ( 100, 'Nokia');
INSERT INTO PRODUCTS VALUES ( 200, 'IPhone'); Date Functions in Hive
INSERT INTO PRODUCTS VALUES ( 300, 'Samsung');
INSERT INTO PRODUCTS VALUES ( 400, 'LG'); SQL Queries Interview Questions - Oracle Part 1
INSERT INTO PRODUCTS VALUES ( 500, 'BlackBerry');
Top Unix Interview Questions - Part 1
INSERT INTO PRODUCTS VALUES ( 600, 'Motorola');
COMMIT; Update Strategy Transformation in Informatica
https://www.folkstalk.com/2012/01/sql-interview-questions-query-part-1.html 1/7
11/29/2018 SQL Query Interview Questions - Part 5
First we will create a target table. The target table will have an additional column INSERT_DATE
to know when a product is loaded into the target table. The target
table structure is
994 have me in circles View all
The next step is to pick 5 products randomly and then load into target table. While selecting
check whether the products are there in the
https://www.folkstalk.com/2012/01/sql-interview-questions-query-part-1.html 2/7
11/29/2018 SQL Query Interview Questions - Part 5
PRODUCT_NAME
FROM PRODUCTS S
WHERE NOT EXISTS (
SELECT 1
FROM TGT_PRODUCTS T
WHERE T.PRODUCT_ID = S.PRODUCT_ID
)
ORDER BY DBMS_RANDOM.VALUE --Random number generator in oracle.
)A
WHERE ROWNUM <= 2;
The last step is to delete the products from the table which are loaded 30 days back.
CONTENT_ID CONTENT_TYPE
-----------------------
1 MOVIE
2 MOVIE
3 AUDIO
4 AUDIO
5 MAGAZINE
6 MAGAZINE
Solution:
First we will create a lookup table where we mention the priorities for the content types. The
lookup table “Create Statement” and data is shown below.
https://www.folkstalk.com/2012/01/sql-interview-questions-query-part-1.html 4/7
11/29/2018 SQL Query Interview Questions - Part 5
Here if LOAD_FLAG is 1, then it indicates which content type needs to be loaded into the target
table. Only one content type will have LOAD_FLAG as 1. The other content types will have
LOAD_FLAG as 0. The target table structure is same as the source table structure.
The second step is to truncate the target table before loading the data
The third step is to choose the appropriate content type from the lookup table to load the source
data into the target table.
UPDATE CONTENTS_LKP
SET LOAD_FLAG = 0
WHERE LOAD_FLAG = 1;
https://www.folkstalk.com/2012/01/sql-interview-questions-query-part-1.html 5/7
11/29/2018 SQL Query Interview Questions - Part 5
UPDATE CONTENTS_LKP
SET LOAD_FLAG = 1
WHERE PRIORITY = (
SELECT DECODE( PRIORITY,(SELECT MAX(PRIORITY) FROM CONTENTS_LKP) ,1 , PRIORIT
FROM CONTENTS_LKP
WHERE CONTENT_TYPE = (SELECT DISTINCT CONTENT_TYPE FROM TGT_CONTENTS)
);
Recommended Posts:
If you like this post, then please share it on Google by clicking on the +1 button.
No comments:
Post a Comment
Publish Preview
https://www.folkstalk.com/2012/01/sql-interview-questions-query-part-1.html 6/7
11/29/2018 SQL Query Interview Questions - Part 5
https://www.folkstalk.com/2012/01/sql-interview-questions-query-part-1.html 7/7