Question 61
HardWhat does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
DBMS
What does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
| 8 | Hari | Sales | NULL | 6 |
SELECT e.name, m.name FROM emp e JOIN emp m ON e.mgr = m.id WHERE e.dept <> m.dept ORDER BY e.id;
Chetan | Anil
Esha | Chetan, Gita | Farhan
Chetan | Anil, Farhan | Anil
Bina | Anil, Chetan | Anil, Farhan | Anil
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
| 8 | Hari | Sales | NULL | 6 |
SELECT dept, COUNT(*), COUNT(salary), AVG(salary) FROM emp GROUP BY dept HAVING COUNT(*) > COUNT(salary);
Sales | 3 | 2 | 38333.33
No rows
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
| 8 | Hari | Sales | NULL | 6 |
SELECT name FROM emp e WHERE salary > (SELECT AVG(salary) FROM emp WHERE dept = e.dept) ORDER BY name;
Anil, Esha, Gita
Anil
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
| 8 | Hari | Sales | NULL | 6 |
SELECT COUNT(*) FROM emp WHERE id NOT IN (SELECT mgr FROM emp);
8
5
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
| 8 | Hari | Sales | NULL | 6 |
SELECT COUNT(*) FROM emp e WHERE NOT EXISTS (SELECT 1 FROM emp s WHERE s.mgr = e.id);
3
4
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
| 8 | Hari | Sales | NULL | 6 |
SELECT name, salary FROM emp WHERE salary IS NOT NULL ORDER BY salary DESC, id LIMIT 1 OFFSET 2;
Esha | 65000
Bina | 70000
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
| 8 | Hari | Sales | NULL | 6 |
SELECT dept, MAX(salary) - MIN(salary) FROM emp GROUP BY dept ORDER BY 2 DESC;
IT | 20000, HR | 15000, Sales | 5000
Sales | 5000, HR | 15000, IT | 20000
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
| 8 | Hari | Sales | NULL | 6 |
SELECT COALESCE(SUM(salary), 0) FROM emp WHERE dept = 'Marketing';
Error
0
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
| 8 | Hari | Sales | NULL | 6 |
SELECT name FROM emp WHERE salary BETWEEN 55000 AND 70000 AND dept IN ('IT', 'Sales') ORDER BY salary, name;
Gita, Farhan, Divya, Bina
Bina, Divya, Farhan, Gita
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table emp:
| id | name | dept | salary | mgr |
|---|---|---|---|---|
| 1 | Anil | IT | 90000 | NULL |
| 2 | Bina | IT | 70000 | 1 |
| 3 | Chetan | HR | 50000 | 1 |
| 4 | Divya | IT | 70000 | 2 |
| 5 | Esha | HR | 65000 | 3 |
| 6 | Farhan | Sales | 55000 | 1 |
| 7 | Gita | Sales | 60000 | 6 |
| 8 | Hari | Sales | NULL | 6 |
SELECT name, DENSE_RANK() OVER (ORDER BY salary DESC) FROM emp WHERE dept = 'IT' ORDER BY 2, name;
Anil | 1, Bina | 2, Divya | 2
Anil | 1, Bina | 2, Divya | 3
Sign up free to see the answer and a step-by-step explanation.
Sales | 3 | 2 | 57500.0
Sales | 3 | 3 | 38333.33
Anil, Esha
Anil, Bina, Divya, Esha, Gita
3
0
0
5
Divya | 70000
Anil | 90000
IT | 20000, Sales | 5000, HR | 15000
IT | 90000, HR | 65000, Sales | 60000
NULL
No rows
Farhan, Gita, Bina, Divya
Farhan, Gita
Anil | 1, Bina | 2, Divya | 4
Bina | 1, Divya | 1, Anil | 3