Mysql 使用联接联合表编辑查询-结果中不需要的列
我需要编辑sql查询以在结果中显示除stuffId之外的每一列。列stuffId仅用于联接目的Mysql 使用联接联合表编辑查询-结果中不需要的列,mysql,sql,Mysql,Sql,我需要编辑sql查询以在结果中显示除stuffId之外的每一列。列stuffId仅用于联接目的 select * from Stuff join ( select stuffId , salary , hireDate , laptop , car from Employee
select
*
from
Stuff
join
(
select
stuffId
, salary
, hireDate
, laptop
, car
from
Employee
union
select
stuffId
, ROUND(Manager.salary + (Manager.salary * cast(bonus as float) / 100), 2) as salary
, hireDate
, laptop
, car
from
Manager
) people
on Stuff.id = people.stuffId
order by
Stuff.id
在
选择中列出所需的列:
select stuff.col1, stuff.col2, . . .,
people.salary, people.hireDate, people.laptop, people.car
. . .
如果只希望stuffId
出现一次,则有一种方法:
select stuff.*, people.salary, people.hireDate, people.laptop, people.car
另一种方法是使用using
而不是on
您的第一行代码请求“*”(所有列)。可以指定要作为输出查看的列。我修改了您的查询,必须删除“ORDER BY Stuff.id”,因为您不希望在输出中使用“id”
select
p.salary
, p.hireDate
, p.laptop
, p.car
from
Stuff s
join
(
select
stuffId
, salary
, hireDate
, laptop
, car
from
Employee
union
select
stuffId
, ROUND(Manager.salary + (Manager.salary * cast(bonus as float) / 100), 2) as salary
, hireDate
, laptop
, car
from
Manager
) people p
on s.id = p.stuffId
您还可以根据自己的喜好从表中选择列。非常适合。我忘了一些基础知识,但现在正在努力。有什么好的课程可以通过练习快速学习SQL查询吗?我也在为C#找一个。