Corobori
Posting Yak Master
105 Posts |
Posted - 2007-10-01 : 19:06:27
|
TablestblGroups defining family of testtblTests all the tests sortedtblTestsDone all the tests done by a studentEach student has to perform the tests for each group in sequence. I am trying to write 2 sql statementsThe 1st one would be showing the next test each student can performThe 2nd one is all the other tests each could perform after having perform the next allowed one1st SQLLooking at the table shown below the result should be for student #1Gr 1, Test 3 (as already performed Te_Id 1 and Te_Id 2 for Gr_Id 1)Gr 2, Test 5 (as he already performed Te_Id 4 for Gr_Id 2 )Gr 3, Test 8 (no tests for Gr_Id 3)2nd SQLGr 2, Test 6Gr 2, Test 7Gr 3, Test 9CREATE TABLE [dbo].[tblGroups] ( [Gr_Id] [int] NOT NULL , [Gr_Desc] [nvarchar] (50) NULL ) ON [PRIMARY]GOINSERT INTO tblGroupsSELECT 1, 'Group 1' UNION ALLSELECT 2, 'Group 2' UNION ALLSELECT 3, 'Another group'GOCREATE TABLE [dbo].[tblTests] ( [Te_Id] [int] NULL , [Te_Gr_Id] [int] NOT NULL , [Te_Nr] [int] NOT NULL ) ON [PRIMARY]GOINSERT INTO tblTestsSELECT 1,1,1 UNION ALLSELECT 2,1,2 UNION ALLSELECT 3,1,3 UNION ALLSELECT 4,2,1 UNION ALLSELECT 5,2,2 UNION ALLSELECT 6,2,3 UNION ALLSELECT 7,2,4 UNION ALLSELECT 8,3,1 UNION ALLSELECT 9,3,2GOCREATE TABLE [dbo].[tblTestsDone] ( [Ted_Id] [int] NULL , [Ted_Te_Id] [int] NULL , [Ted_St_Id] [int] NULL , [Ted_Status] [int] NULL ) ON [PRIMARY]GOINSERT INTO tblTestsDoneSELECT 1,1,1,1 UNION ALLSELECT 1,2,1,1 UNION ALLSELECT 1,4,1,1jean-lucwww.corobori.com |
|