|
|
|
Click here to copy the following block | create table #Topic ( TopicID char(2) not null primary key , TopicName varchar(32) not null ) create table #Seminar ( SeminarID int not null primary key , TopicID char(2) not null foreign key references #Topic(#TopicID) ) create table #Registrant ( RegistrantID int not null primary key , SeminarID int not null foreign key references Seminar(SeminarID) ) go insert into #Topic values ( 'BR','How to be the Best Receptionist' ) insert into #Topic values ( 'AC','Advanced Coding' ) insert into #Topic values ( 'IP','Insurance Processing' )
insert into #Seminar values ( 1 , 'BR' ) insert into #Seminar values ( 2 , 'IP' ) insert into #Seminar values ( 3 , 'AC' ) insert into #Seminar values ( 4 , 'AC' ) insert into #Seminar values ( 5 , 'BR' ) insert into #Seminar values ( 6 , 'BR' )
insert into #Registrant values ( 1 , 1 ) insert into #Registrant values ( 2 , 2 ) insert into #Registrant values ( 3 , 1 ) insert into #Registrant values ( 4 , 3 ) insert into #Registrant values ( 5 , 1 ) insert into #Registrant values ( 6 , 2 ) insert into #Registrant values ( 7 , 4 ) insert into #Registrant values ( 8 , 2 ) insert into #Registrant values ( 9 , 3 ) insert into #Registrant values ( 10 , 1 )
SELECT * FROM #Topic AS t JOIN #Seminar AS s ON s.TopicID = t.Topicid JOIN #Registrant r ON r.seminarid = s.seminarid ORDER BY t.Topicid, s.seminarid , r.registrantid
SELECT t.TopicID , t.TopicName , ( SELECT COUNT( DISTINCT s.SeminarID ) FROM #Seminar AS s WHERE s.TopicID = t.TopicID ) AS Seminars , ( SELECT COUNT( DISTINCT r.RegistrantID ) FROM #Registrant AS r JOIN #Seminar AS s ON r.SeminarID = s.SeminarID WHERE s.TopicID = t.TopicID ) AS Registrants FROM #Topic AS t ORDER BY t.TopicID
|
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|