注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
本帖最后由 黑发如漆的排球 于 2023-1-29 20:03 编辑
SQL练习题第二弹!-baidu 1point3acres
Q1. Write an SQL query to fetch “FIRST_NAME” from Worker table using the alias name as <WORKER_NAME>.
Ans.
The required query is:
Select FIRST_NAME AS WORKER_NAME from Worker;. Waral dи,
Q2. Write an SQL query to fetch “FIRST_NAME” from Worker table in upper case.
Ans.
The required query is:
Select upper(FIRST_NAME) from Worker;. 1point 3acres
Q3. Write an SQL query to fetch unique values of DEPARTMENT from Worker table..
Ans.
The required query is:
Select distinct DEPARTMENT from Worker;. From 1point 3acres bbs
Q4. Write an SQL query to print the first three characters of FIRST_NAME from Worker table.
Ans.-baidu 1point3acres
The required query is:. .и
Select substring(FIRST_NAME,1,3) from Worker;
Q5. Write an SQL query to find the position of the alphabet (‘a’) in the first name column ‘Amitabh’ from Worker table.. 1point 3acres
Ans.
The required query is:
Select INSTR(FIRST_NAME, BINARY'a') from Worker where. Waral dи,
FIRST_NAME = 'Amitabh';
Notes. ..
• The INSTR method is in case-sensitive by defaul with salaries >= 50000 and <= 100000.
Ans.. From 1point 3acres bbs
The required query is:
SELECT CONCAT(FIRST_NAME, ' ', LAST_NAME) As
Worker_Name, Salary
FROM worker
WHERE WORKER_ID IN
(SELECT WORKER_ID FROM worker
WHERE Salary BETWEEN 50000 AND 100000);.--
Q23. Write an SQL query to fetch the no. of workers for each department in the descending order.
Ans.
The required query is:.
SELECT DEPARTMENT, count(WORKER_ID) No_Of_Workers
FROM worker
GROUP BY DEPARTMENT. 1point3acres
ORDER BY No_Of_Workers DESC;
Q24. Write an SQL query to print details of the Workers who are also Managers.. check 1point3acres for more.
Ans.. 1point3acres
The required query is:
SELECT DISTINCT W.FIRST_NAME, T.WORKER_TITLE
FROM Worker W
INNER JOIN Title T. 1point3acres.com
ON W.WORKER_ID = T.WORKER_REF_ID
AND T.WORKER_TITLE in ('Manager'); |