0% found this document useful (0 votes)
42 views

SQL Assessment

Uploaded by

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

SQL Assessment

Uploaded by

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

Question

Which one is correct to get the last id?


Which one is correct to get even number records?
If table A contains 100 records, table B contains 90 records and common records are 30 (as per unique id's from
are available?
Which one is true to give alias name for a column name "id" as "emp_id"?
Which one is true to print the first 3 characters of first_name From Employee table?
Which one of the following statement is true to print the "department" from Orders table after removing white s
Which one is correct to print details of the employees whose FIRST_NAME contains ‘K’?
Find the SQL statement below that is equal to the following:

SELECT name
What will FROM
be the customer
result WHERE
of the query state = 'VA';
below?
select case when null = null then 'Y' else 'N' end as Result;
Which one of the following statement is true to show the 2 highest salary from Employee table?
Option A
select id from table order by id desc limit 1
Select * from table where id % 2 != 0

100

SELECT id AS emp_id FROM Employee;


SELECT substring(first_name,3,1) FROM Employee;
SELECT TRIM(department) FROM Orders;
SELECT * FROM Employees WHERE FIRST_NAME like
'K';
SELECT name IN customer WHERE state IN ('VA');
Y
SELECT MAX(salary) from Employee;
Option B
select id from table order by id asc limit 1
Select * from table where id % 2 = 0

90

SELECT id FROM Employee;


SELECT substring(first_name,1,3) FROM Employee;
SELECT LTRIM(department) FROM Orders;
SELECT * FROM Employees WHERE FIRST_NAME like
'%K';
SELECT name IN customer WHERE state = 'VA';
N
SELECT MAX(salary) from Employee
WHERE salary in (SELECT MAX(Salary) from Employee);
Option C
select id from table limit 1
Select * from table where id = 2

30

SELECT emp_id FROM Employee;


SELECT substring(first_name,0,3) FROM Employee;
SELECT RTRIM(department) FROM Orders;
SELECT * FROM Employees WHERE FIRST_NAME like 'K
%';
SELECT name IN customer WHERE state = 'V';
NULL
SELECT MAX(salary) from Employee
WHERE salary not in (SELECT MAX(Salary) from
Employee);
Answe
Option D
r
None are true
Select * from table where id != 2

9000

All are true


SELECT substring(first_name,3,0) FROM Employee;
SELECT MTRIM(department) FROM Orders;
SELECT * FROM Employees WHERE FIRST_NAME like '%K
%';
SELECT name FROM customer WHERE state IN ('VA');
None are true
SELECT salary from Employee
WHERE salary not in (SELECT MAX(Salary) from Employee);
Create an SQL query that shows the TOP 3 Associates who has
Question
the most productivity in total ?
Table Associates Table Production

Name Process Process Productivity


name_1 process_1 process_1 1000
name_1 process_2 process_2 1500
name_2 process_3 process_3 34000
name_2 process_4 process_4 29000
name_2 process_5 process_5 40000
name_3 process_6 process_6 4400
… … … …

Answer:
order_date_time.
Question
Write an SQL query to find out how many users toouched more than 1000 but less than 2000 or
Table event_log

user_id order_date_time
7494212 1535308430
7494212 1535308433
1475185 1535308444
6946725 1535308475
6946725 1535308476
6946725 1535308477
… …

Answer:
but less than 2000 orders
Question Write a query that every department where the average salary per employee is lower th

Table Employees Table

department_name employee_id employee_name salary


Sales 123 John Doe 500
Sales 211 Jane Smith 600
HR 556 Billy Bob 1000
Sales 711 Robert Hayek 400
Marketing 235 Edward Jorgson 1200
Marketing 236 Christine Packard 200
… … … …

Answer:
per employee is lower than 500?

Salaries

employee_idemployee_name
123 John Doe
211 Jane Smith
556 Billy Bob
711 Robert Hayek
235 Edward Jorgson
236 Christine Packard
… …
Question SELECT name FROM Customers WHERE referredby <> 2;

Table Customers

id name referredby
1 John NULL
2 Jane NULL
3 Anne 2
4 Eric NULL
5 Pat 1
6 Alice 2

Answer:
Write a SQL query to return a list of all the invoices?
Question

Table Invoices Table

col_name data_type allow_nulls col_name


id int no id
Billingdate date no name
customerid int no referredby

Answer:
Customers

data_type allow_nulls
int no
varchar no
int Yes
Question
Write a query to find duplicate records with one filed name?

Table Users

name email
John John@
Jane Jane@
Alice Alice@
Lisa Lisa@

Answer:
Question Write a Query from below input table to get the output table results?

Input Table Employee

id name production manager_id manager_i


10 Anil 50000 18
11 Vikas 75000 16
12 Nisha 40000 18
13 Nidhi 60000 17
14 Priya 80000 18
15 Mohit 45000 18
16 Rajesh 90000 –
17 Raman 55000 16
18 Santosh 65000 17

Answer:
ults?

Results Table Output

manager_id manager avg_salary_under_manager


16 Rajesh 65000
17 Raman 62500
18 Santosh 53750
Question Write a Query from below input table to get the output table results?

Input Table Quality Results Table Output

quality quality int


99.12 99.12 99
87.34 87.34 87
52.67 52.67 52
63.48 63.48 63
86.48 86.48 86

Answer:
ults?

decimal
12
34
67
48
48
Write a single query to calculate the sum of all positive values of profit column and the s
Question
below table?.

Table Sales

profit
10000
5800
-5200
-48000
65000
35000
-12004
4500
-1000

Answer:
f profit column and the sum of all negative values of profit column from the
Question SELECT * FROM Runners WHERE id NOT IN (SELECT winner_id FROM Races)

Table Runners Table Races

id name id event
1 John 1 100 Meter
2 Jane 2 500 Meter
3 Alice 3 200 Meter
4 Bobby 4 1000 Meter
5 Lisa

Answer:
ROM Races)

winner_id
2
3
2
NULL

You might also like