Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.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
Sql 如何以其他方式左连接列_Sql_Sql Server - Fatal编程技术网

Sql 如何以其他方式左连接列

Sql 如何以其他方式左连接列,sql,sql-server,Sql,Sql Server,我想将右列映射到左列,但select语句出现错误,因为“select”附近的语法不正确。应为ID create table [AdventureWorks2014].[abc] as select a.*, b.* from [Production].[Product] a left join( select distinct ProductID,Shelf from [Production].[ProductInventory] )b on a.ProductID = b. P

我想将右列映射到左列,但select语句出现错误,因为“select”附近的语法不正确。应为ID

create table [AdventureWorks2014].[abc] as
select a.*,
        b.*
from [Production].[Product] a
left join(
select distinct ProductID,Shelf
from [Production].[ProductInventory]
)b
on a.ProductID = b. ProductID;

尝试使用
选择进入

select p.*, pi.shelf
into [AdventureWorks2014].[abc]
from [Production].[Product] p left join
     (select distinct ProductID, Shelf
      from [Production].[ProductInventory] pi
     ) pi
     on p.ProductID = pi.ProductID;
注:

  • 我不知道SQL Server支持将表创建为
  • 表中的列需要有唯一的名称。如果使用
    *
    ,您将获得
    ProductId
    两次
  • 表名的缩写是最好的命名约定;应避免使用无意义的字母,如
    a
    b

    • 尝试使用
      选择进入

      select p.*, pi.shelf
      into [AdventureWorks2014].[abc]
      from [Production].[Product] p left join
           (select distinct ProductID, Shelf
            from [Production].[ProductInventory] pi
           ) pi
           on p.ProductID = pi.ProductID;
      
      注:

      • 我不知道SQL Server支持将表创建为
      • 表中的列需要有唯一的名称。如果使用
        *
        ,您将获得
        ProductId
        两次
      • 表名的缩写是最好的命名约定;应避免使用无意义的字母,如
        a
        b

      您是否也在尝试创建表?您使用的是哪种DBMS?您是否也在尝试创建表?您使用的是哪种DBMS?