如何在我的SQL腳本中添加子查詢作爲列?如何在SQL中添加子查詢作爲列
例如
Select emp_no, name,gender ,
(select department_name from departments where employees.emp_no = departments.emp_no)
from employees
PS:我使用Oracle 8
如何在我的SQL腳本中添加子查詢作爲列?如何在SQL中添加子查詢作爲列
例如
Select emp_no, name,gender ,
(select department_name from departments where employees.emp_no = departments.emp_no)
from employees
PS:我使用Oracle 8
你似乎缺少性別後逗號。
Select emp_no, name,gender ,
(select department_name from departments where employees.emp_no = departments.emp_no) as dept_name from employees
以下是您需要的。在性別後添加逗號。這個子查詢需要爲每個結果返回一行,否則會出現錯誤。
Select emp_no, name,gender,
(select department_name from departments where employees.emp_no = departments.emp_no)
from employees
這看起來相當健康,我會建議一些(可能的拼寫錯誤)清理:後「性別」添加一個逗號和申報表名,還設置了子查詢的別名
Select employees.emp_no, employees.name, employees.gender,
(select departments.department_name from departments where employees.emp_no = departments.emp_no) as dept_name
from employees
或者,一個漂亮的加入會會的工作也一樣,如果其他數據是可行的:
Select employees.emp_no, employees.name, employees.gender, departments.department_name
from employees
inner join departments on employees.emp_no = departments.emp_no
該查詢你的答案,但如果有一種人只會工作因爲如果我們使用多於一列的話,它將會重演一個錯誤。
"Select employee_id,first_name,
(select department_name,manager_id from departments where employees.department_id = departments.department_id) as new_column
from employees;"
你可以試試這個:
SELECT em.emp_no, em."name",em.gender , (SELECT
不同dp.department_name FROM departments dp WHERE em.emp_no = dp.emp_no) my_sub FROM employees em
1.報價gender' 2.後'如果返回單行 - 它應該工作 – zerkms
亂猜,而是逗號 – SS781
逗號不是問題,我只是錯誤地輸入了這個查詢。這個查詢的結果是在子查詢SELECT部分 – rjmcb