具体想要实现的如图:要如何由MergeYield表 和 Single表通过sql 实现Details表的查询?
所用的的资料下面有贴出..
USE [TSQLPractice] GO /****** Object: Table [dbo].[MergeYield] Script Date: 2014/12/10 星期三 下午 05:21:30 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[MergeYield]( [DeptNo] [nchar](10) NULL, [OrderNo] [nchar](10) NULL, [Qty] [nchar](10) NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[SingleYield] Script Date: 2014/12/10 星期三 下午 05:21:30 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[SingleYield]( [DeptNo] [nchar](10) NULL, [OrderNo] [nchar](10) NULL, [QTY] [nchar](10) NULL ) ON [PRIMARY] GO INSERT [dbo].[MergeYield] ([DeptNo], [OrderNo], [Qty]) VALUES (N'E01 ', N'PM-1411025', N'458 ') INSERT [dbo].[MergeYield] ([DeptNo], [OrderNo], [Qty]) VALUES (N'E01 ', N'PM-1411026', N'756 ') INSERT [dbo].[MergeYield] ([DeptNo], [OrderNo], [Qty]) VALUES (N'E01 ', N'PM-1411027', N'1254 ') INSERT [dbo].[MergeYield] ([DeptNo], [OrderNo], [Qty]) VALUES (N'E02 ', N'PM-1412001', N'1423 ') INSERT [dbo].[MergeYield] ([DeptNo], [OrderNo], [Qty]) VALUES (N'E02 ', N'PM-1412002', N'741 ') INSERT [dbo].[MergeYield] ([DeptNo], [OrderNo], [Qty]) VALUES (N'E02 ', N'PM-1412003', N'654 ') INSERT [dbo].[MergeYield] ([DeptNo], [OrderNo], [Qty]) VALUES (N'E03 ', N'PM-1412099', N'756 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E01A ', N'PM-1411025', N'300 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E01B ', N'PM-1411025', N'100 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E01C ', N'PM-1411025', N'58 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E01A ', N'PM-1411026', N'400 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E01B ', N'PM-1411026', N'350 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E01B ', N'PM-1411026', N'1000 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E01B ', N'PM-1411026', N'254 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E02A ', N'PM-1412001', N'800 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E02A ', N'PM-1412001', N'600 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E03B ', N'PM-1412099', N'700 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E02B ', N'PM-1412002', N'700 ') INSERT [dbo].[SingleYield] ([DeptNo], [OrderNo], [QTY]) VALUES (N'E02A ', N'PM-1412003', N'650 ')