求SQL语句..在线给分
表DocSend
DOCID SendID SendUserID SendNodeID SendDate
4 1 1 1 2004-5-1
4 2 2 2 2004-5-2
4 3 3 2 2004-5-2
表DocWait
ID DocID SendID WaitUserID WaitNodeID
1 4 1 2 2
2 4 1 3 2
3 4 2 4 3
4 4 3 5 3
现要对以上两表进行合并,成一张表。
注:两表的SendID 进行关联,现要产生一张树形表(不要求位置).
DOCID NewID SendUserID SendNodeID SendDate parentID
4 1 1 1 2004-5-1 0
4 2 2 2 2004-5-2 4
4 3 3 2 2004-5-2 5
4 4 2 2 2004-5-1 1
4 5 3 2 2004-5-2 1
4 6 4 3 2004-5-2 2
4 7 4 3 2004-5-2 3
CREATE TABLE [DocSend] (
[DocID] [int] NULL ,
[SendID] [int] IDENTITY (1, 1) NOT NULL ,
[SendUserID] [int] NULL ,
[SendNodeID] [int] NULL ,
[SendDate] [datetime] NULL CONSTRAINT [DF_DocSend_SendDate] DEFAULT (getdate())
) ON [PRIMARY]
GO
CREATE TABLE [DocWait] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[DocID] [int] NULL ,
[SendID] [int] NULL ,
[WaitUserID] [int] NULL ,
[WaitNodeID] [int] NULL ,
) ON [PRIMARY]
GO
------解决方案--------------------不明白,SendNodeID WaitNodeID什么意思?
------解决方案--------------------parentID怎么来得?
------解决方案--------------------那你上边两个表里都没