表联接问题。。。很基础
生产单表
CREATE TABLE [TProductionOrder] ( [Fid] [int] IDENTITY (1, 1) NOT NULL , [FProductionOrderNo] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL , [FOrderAdmin_PersonId] [int] NULL CONSTRAINT [DF__TProducti__FOrde__73BA3083] DEFAULT (0), [FDevelopStateId] [int] NULL CONSTRAINT [DF__TProducti__FDeve__74AE54BC] DEFAULT (0), [FProductionPrgoressId] [int] NULL CONSTRAINT [DF__TProducti__FProd__75A278F5] DEFAULT (0), [FProductId] [int] NULL CONSTRAINT [DF__TProducti__FProd__76969D2E] DEFAULT (0), [FCustomerModelId] [int] NULL CONSTRAINT [DF__TProducti__FCust__778AC167] DEFAULT (0), [FProductionNum] [int] NULL CONSTRAINT [DF__TProducti__FProd__787EE5A0] DEFAULT (0), [FRequireTime] [datetime] NULL , [FProductionAddTimer] [datetime] NULL , [FTradeAuditer_PersonId] [int] NULL CONSTRAINT [DF__TProducti__FTrad__797309D9] DEFAULT (0), [FTradeStateId] [int] NULL CONSTRAINT [DF__TProducti__FTrad__7A672E12] DEFAULT (0), [FTradeAuditTime] [datetime] NULL , [FFinishTime] [datetime] NULL , [FRemark] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL , [Fverify_PersonId] [int] NULL CONSTRAINT [DF__TProducti__Fveri__7B5B524B] DEFAULT (0), [FVerify_timer] [datetime] NULL , [FSingleValue] [money] NULL CONSTRAINT [DF__TProducti__FSing__7C4F7684] DEFAULT (0), [FSingleValue_PersonId] [int] NULL CONSTRAINT [DF__TProducti__FSing__7D439ABD] DEFAULT (0), [FSingleValueTimer] [datetime] NULL , [FInvaild] [bit] NOT NULL CONSTRAINT [DF__TProducti__FInva__7E37BEF6] DEFAULT (0), [FKitCost] [money] NULL CONSTRAINT [DF__TProducti__FKitC__7F2BE32F] DEFAULT (0), [FProductionCost] [money] NULL CONSTRAINT [DF__TProducti__FProd__00200768] DEFAULT (0), CONSTRAINT [aaaaaTProductionOrder_PK] PRIMARY KEY NONCLUSTERED ( [Fid] ) ON [PRIMARY] ) ON [PRIMARY]GO
CREATE TABLE [TPerson] ( [Fid] [int] IDENTITY (1, 1) NOT NULL , [FPersonName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL , [FDepartmentId] [int] NULL CONSTRAINT [DF__TPerson__FDepart__412EB0B6] DEFAULT (0), [FPermissionId] [int] NULL CONSTRAINT [DF__TPerson__FPermis__4222D4EF] DEFAULT (0), [FPositionId] [int] NULL CONSTRAINT [DF__TPerson__FPositi__4316F928] DEFAULT (0), [FMachineAddr] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL , [FInvaild] [bit] NOT NULL CONSTRAINT [DF__TPerson__FInvail__440B1D61] DEFAULT (0), CONSTRAINT [aaaaaTPerson_PK] PRIMARY KEY NONCLUSTERED ( [Fid] ) ON [PRIMARY] ) ON [PRIMARY]用生产单表中的 [FOrderAdmin_PersonId] , [FTradeAuditer_PersonId] ,[Fverify_PersonId] ,[FSingleValue_PersonId] 都联结到 人员表的怎么写用 select 子查询貌似可以,用联接,我不会 - -,求教GO
select * from TProductionOrder t1 left join TPerson t2 on t1.FOrderAdmin_PersonId=t2.Fidleft join TPerson t3 on t1.FTradeAuditer_PersonId=t3.Fidleft join TPerson t4 on t1.Fverify_PersonId=t4.Fidleft join TPerson t5 on t1.FSingleValue_PersonId=t5.Fid
[解决办法]
可以, 你就 t1.字段1,t2.字段2,t2.字段……