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 |
vjs2445
Starting Member
16 Posts |
Posted - 2014-01-16 : 15:56:36
|
I need some help in writing SQL.Following is the table as well result I am trying to get: Col1 Col2 A N A M B N C M D N D M Result A N A M D N D MI am looking for the rows which has both N and M value.Thanks in advance |
|
nagino
Yak Posting Veteran
75 Posts |
Posted - 2014-01-16 : 19:05:05
|
If Col2 have only 'N' or 'M', How dose that look?------------------------------------------------#TBL mean 'the table'SELECT Col1, Col2FROM #TBLWHERE EXISTS ( SELECT * FROM #TBL FILTER WHERE #TBL.Col1 = FILTER.Col1 AND #TBL.Col2 != FILTER.Col2) -------------------------------------From JapanSorry, my English ability is limited. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-17 : 02:14:31
|
quote: Originally posted by vjs2445 I need some help in writing SQL.Following is the table as well result I am trying to get: Col1 Col2 A N A M B N C M D N D M Result A N A M D N D MI am looking for the rows which has both N and M value.Thanks in advance
SELECT Col1,Col2FROM(SELECT MAX(Col2) OVER (PARTITION BY Col1) AS MaxCol2,MIN(Col2) OVER (PARTITION BY Col1) AS MinCol2,*FROM TableWHERE Col2 IN ('M','N'))tWHERE MaxCol2 <> MinCol2 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
vjs2445
Starting Member
16 Posts |
Posted - 2014-01-17 : 10:28:38
|
Thanks for the help.Regards, |
|
|
|
|
|