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 |
daddyjmo
Starting Member
2 Posts |
Posted - 2013-12-06 : 14:41:29
|
Distinct name that match both subjects (math, science) from classname in level 2 only. Not sure where to even start. Any help is greatly appreciated! Sorry for the crude example table below:name subject levelbob math 2hank math 1joe science 2bob science 2joe math 2ben science 2carl science 1 |
|
daddyjmo
Starting Member
2 Posts |
Posted - 2013-12-06 : 14:43:02
|
So basically return set should return bob and joe because they both have math and science at level 2 only. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-07 : 08:22:04
|
[code]SELECT nameFROM tableGROUP BY nameHAVING COUNT(DISTINCT CASE WHEN subject IN ('math','science') AND level = 2 THEN subject END) =2[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|