Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
vishva
Starting Member
1 Post |
Posted - 2014-04-18 : 05:37:14
|
COURSE_REFERENCE SESSION_ID---------------- ----------1781185018 2014-04-18S08.45E10.00-497192093 2014-04-18S08.45E10.00In the above table session_id(timings) is same for both courses(1781185018, -497192093), So now i want to find out the clashes as belowCOURSE_REFERENCE1 COURSE_REFERENCE2 CLASH_COUNT ---------------- ----------------- -----------1781185018 -497192093 2 |
|
MuralikrishnaVeera
Posting Yak Master
129 Posts |
Posted - 2014-04-18 : 06:33:05
|
[code]DECLARE @TEMP TABLE(COURSE_REFERENCE INT ,SESSION_ID VARCHAR(MAX))INSERT INTO @TEMP VALUES(1781185018, '2014-04-18S08.45E10.00'),(-497192093, '2014-04-18S08.45E10.00')--Method_1 :SELECT [1781185018] AS CourseID_1,[-497192093] AS CourseID_2,(SELECT count(SESSION_ID) FROM @TEMP WHERE SESSION_ID=SESSION_ID)AS NoOfClashes FROM @TEMP PIVOT( MAX(COURSE_REFERENCE) FOR COURSE_REFERENCE IN ([1781185018],[-497192093]))Pvt--Method_2 :SELECTT1.COURSE_REFERENCE course_id1,T2.COURSE_REFERENCE course_id2,(SELECT count(SESSION_ID) FROM @TEMP WHERE SESSION_ID=SESSION_ID)AS NoOfClashesFROM @TEMP T1INNER JOIN @TEMP T2ON T1.COURSE_REFERENCE < T2.COURSE_REFERENCEAND T1.SESSION_ID = T2.SESSION_ID[/code]---------------Murali KrishnaYou live only once ..If you do it right once is enough....... |
|
|
|
|
|