Author |
Topic |
rajnidas
Yak Posting Veteran
97 Posts |
Posted - 2013-11-11 : 08:04:24
|
hi everyone,i am using table of student stdid name subject year1 arun chemistry 19962 alias maths 19963 babau history 19974 basha hindi 19985 hussain hindi 20016 chandru chemistry 20017 mani hindi 20028 rajesh history 20039 rama chemistry 200810 laxman maths 200811 naryan tamil 201012 das chemistry 2010i want all records except chemistry and if chemistry records is there i want to avoid that year for all records also. pls i need help thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-11 : 08:12:28
|
do you mean this?select stdid, name, subject, [year]from(select *,sum(case when subject='chemistry' then 1 else 0 end) over (partition by student,[year]) as cntfrom student)twhere cnt=0 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
rajnidas
Yak Posting Veteran
97 Posts |
Posted - 2013-11-11 : 23:28:55
|
thanks visakh murukes sir,but i want , if chemistry like this ,stdid name subject year1 arun chemistry 19962 alias maths 1996if chemistry year 1996, then all subject in 1996 also not to display. pls... |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2013-11-12 : 00:10:25
|
this ?select *from student swhere not exists ( select * from student x where x.year = s.year and x.subject = 'chemistry' ) if not, please post your expected result KH[spoiler]Time is always against us[/spoiler] |
|
|
rajnidas
Yak Posting Veteran
97 Posts |
Posted - 2013-11-12 : 01:42:10
|
thanks sir,my query is if chemistry subject is year of 1996 then whatever recored on year of 1996 also not to display.result would be except subject chemistry and year 1996.stdid name subject year1 arun chemistry 19962 alias maths 1996thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-12 : 01:42:50
|
quote: Originally posted by rajnidas thanks visakh murukes sir,but i want , if chemistry like this ,stdid name subject year1 arun chemistry 19962 alias maths 1996if chemistry year 1996, then all subject in 1996 also not to display. pls...
select stdid, name, subject, [year]from(select *,sum(case when subject='chemistry' then 1 else 0 end) over (partition by [year]) as cntfrom student)twhere cnt=0 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
rajnidas
Yak Posting Veteran
97 Posts |
Posted - 2013-11-12 : 01:55:49
|
thank you so much visakh murukes sir ,i am so happy for 2 days searching for this solution |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-12 : 02:00:36
|
you're welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-12 : 02:01:05
|
Just FYI Tans solution should also work for you------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|