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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 column value as record....

Author  Topic 

kooka
Starting Member

4 Posts

Posted - 2009-11-23 : 19:24:53
SELECT *
FROM Table1 T1
JOIN Table2 T2
On T1.IDT1 = T2.IDT2
JOIN Table3 T3
On T2.IDT2 = T3.IDT3


Let’s say,
T1 has IDT1, IDT2, min, max
T2 has IDT2, IDT3
T3 has IDT3, kind

T3 has values like
1 , A
2, B

I want to get the data like
IDT1 , min (tied with A value of “kind” column) , max( tied with A value of “kind” column) , min (tied with B value of “kind” column) , max( tied with B value of “kind” column) ,

Please, tell me what will be the query?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-11-27 : 02:35:00
do you mean this?

SELECT IDT1,
MIN(CASE WHEN kind='A' THEN somecol ELSE END) AS MinA,
MAX(CASE WHEN kind='A' THEN somecol ELSE END) AS MaxA,
MIN(CASE WHEN kind='B' THEN somecol ELSE END) AS MinB,
MAX(CASE WHEN kind='B' THEN somecol ELSE END) AS MaxB
FROM T1 t1
JOIN T2 t2
ON t2.IDT2=t1.IDT2
JOIN T3 t3
ON t3.IDT3 = t2.IDT3
GROUP BY IDT1
Go to Top of Page
   

- Advertisement -