gpt4 book ai didi

mysql - 如何在MySQL中引用SELECT语句结果表?

转载 作者:行者123 更新时间:2023-11-29 08:07:22 25 4
gpt4 key购买 nike

我有两个非常简单的问题:

  1. MySQL 中 select 语句结果表的名称是什么(我可以在另一个 select 语句中使用的名称,例如下一行)?
  2. 如何命名上表(问题 1 中)?

最佳答案

1- what is name of a select statement result table of in mysql?(a name that I can use it in another select statement(for example in next line))

除非您在执行时定义别名,否则结果集不会有任何名称。

select * from department dept

在上面的示例中,deptdepartment 表的别名。

2- how to naming that above table(in question 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: Schema Object Names

关于mysql - 如何在MySQL中引用SELECT语句结果表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22435370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com