gpt4 book ai didi

mysql - 使用联合表编辑查询 - 结果中不需要的列

转载 作者:行者123 更新时间:2023-11-29 06:17:05 25 4
gpt4 key购买 nike

我需要编辑 sql 查询以在结果中显示除 stuffId 之外的每一列。列 stuffId 仅用于连接目的。

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 中列出您想要的列:

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

关于mysql - 使用联合表编辑查询 - 结果中不需要的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35247340/

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