[英]MySQL SELECT in a UNION statement is not able to refer to the parent table
[英]How to refer to a SELECT statement result table in MySQL?
我有兩個非常簡單的問題:
1- mysql中select語句結果表的名稱是什么?(我可以在另一個select語句中使用它的名稱(例如在下一行))
除非您在執行時定義別名,否則Resultsets將沒有任何名稱。
select * from department dept
在上面的示例中, dept
是department
表的別名。
2-如何命名上表(問題1)?
可能存在從單個或多個表中選擇信息並連接在一起的情況。 對於整個集合,您可以定義別名。
select
emp_id, salary, commission,
( salary + commission ) as total_sal,
dept.dept_name as department_name
from employee emp, department dept
where emp.dept_no = dept.dept_no
對於上面的查詢,您可以在使用時給出別名,如:
select * from (
select
emp_id, salary, commission,
( salary + commission ) as total_sal,
dept.dept_name as department_name
from employee emp, department dept
where emp.dept_no = dept.dept_no
) as filtered_results
where
department_name in ( 'sales', 'marketing' )
參考 :
MySQL:架構對象名稱
如果我是正確的,你希望在mysql中創建一個select命令嗎? 這應該工作。
CREATE TABLE fishTypes (type VARCHAR(100)) SELECT type FROM allFish;
這是您正在尋找的解決方案嗎? 這里allFish可能有架構(number INT, type VARCHAR(100))
它被找到了。 我必須使用意見。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.