0% found this document useful (0 votes)
16 views3 pages

SQL Updated Test

This document contains 5 questions related to SQL queries: 1. Write a query to print the name of employees having the 2nd highest salary in each department from a table with columns for Name, Department, and Salary. 2. Write a query to list users who took the same training lesson more than once in a day, grouped by user and training lesson ordered from most recent to oldest date. 3. Asks about what an execution plan is, when you would use it, how to view it, and what information it contains. 4. Write a dynamic query to insert country short forms and full forms from a variable into a table with two columns. 5. Write a dynamic

Uploaded by

Sreni K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

SQL Updated Test

This document contains 5 questions related to SQL queries: 1. Write a query to print the name of employees having the 2nd highest salary in each department from a table with columns for Name, Department, and Salary. 2. Write a query to list users who took the same training lesson more than once in a day, grouped by user and training lesson ordered from most recent to oldest date. 3. Asks about what an execution plan is, when you would use it, how to view it, and what information it contains. 4. Write a dynamic query to insert country short forms and full forms from a variable into a table with two columns. 5. Write a dynamic

Uploaded by

Sreni K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Write an SQL query to print the name of


employees having the 2nd highest salary in each
department.
Assume a table with 3 columns
Name of the employee, Department and Salary

Table for Que. No. 2


Given the following tables:
SELECT * FROM users

user_id username
1 John Doe
2 Jane Don
3 Alice Jones
4 Lisa Romero

SELECT * FROM training_details

user_training_id user_id training_id training_date


1 1 1 "2015-08-02"
2 2 1 "2015-08-03"
3 3 2 "2015-08-02"
4 4 2 "2015-08-04"
5 2 2 "2015-08-03"
6 1 1 "2015-08-02"
7 3 2 "2015-08-04"
8 4 3 "2015-08-03"
9 1 4 "2015-08-03"
10 3 1 "2015-08-02"
11 4 2 "2015-08-04"
12 3 2 "2015-08-02"
13 1 1 "2015-08-02"
14 4 3 "2015-08-03"

2. Write a query to get the list of users who took


the training lesson more than once in the same
day, grouped by user and training lesson each
ordered from the most recent lesson date to oldest
date.

3. What is an execution plan? When would you use


it? How would you view the execution plan? What
all you’ll see in an execution plan?

4. Define a variable with Varchar 1000 and assign


the value ‘IND-India,JPN-Japan,US-United States’
This string can be of any length.
Write a dynamic query to insert data in a table with
two columns column 1 should have Country Short
Form and column 2 should have Country Full Form.
Output should be: -
Short Form Full Form
IND India
JPN Japan
US United States

5. Write the dynamic query in most optimum way

Insert numbers in a table from 1-1000, Numbers


which are divisible by 3 Print ‘Fizz’, Numbers which
are divisible by 5 Print ‘Buzz’ and Numbers divisible
by both 3 and 5 Print ‘FizzBuzz’

Output
1 Null
2 Null
3 Fizz
4 Null
5 Buzz
6 Fizz
7 Null
8 Null
9 Fizz
10 Buzz
11 Null
12 Fizz
13 Null
14 Null
15 FizzBuzz
16 Null

You might also like