Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 使用联接联合表编辑查询-结果中不需要的列_Mysql_Sql - Fatal编程技术网

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

Mysql 使用联接联合表编辑查询-结果中不需要的列,mysql,sql,Mysql,Sql,我需要编辑sql查询以在结果中显示除stuffId之外的每一列。列stuffId仅用于联接目的 select * from Stuff join ( select stuffId , salary , hireDate , laptop , car from Employee

我需要编辑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 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#找一个。