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
 Query Help, please!

Author  Topic 

angel9
Starting Member

10 Posts

Posted - 2009-04-08 : 09:52:03
Please help on the following query:

Exclude students who receive S loan and NO P loan and have 6 or more credit hours. (Select statement only)

Your help is greatly appreciated again.

Original table looks like this;
ID CREDIT DETAIL_CODE CAT_CODE
1 9 S FA
1 4 P FA
2 3 S FA
2 4 P FA
3 9 S FA
4 3 S FA


Results will look like this:
ID CREDIT DETAIL_CODE CAT_CODE
1 9 S FA
1 4 P FA
2 3 S FA
2 4 P FA
4 3 S FA

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-08 : 10:11:24
select * from your_table as t1
inner join
(
select id from your_table
group by id
having sum(case when DETAIL_CODE ='S' and credit>6 then 1 else 2 end)>1
) as t2
on t1.id=t2.id


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

angel9
Starting Member

10 Posts

Posted - 2009-04-08 : 13:33:07
It is great! thank you very much for your help!

quote:
Originally posted by madhivanan

select * from your_table as t1
inner join
(
select id from your_table
group by id
having sum(case when DETAIL_CODE ='S' and credit>6 then 1 else 2 end)>1
) as t2
on t1.id=t2.id


Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-09 : 02:16:36
quote:
Originally posted by angel9

It is great! thank you very much for your help!

quote:
Originally posted by madhivanan

select * from your_table as t1
inner join
(
select id from your_table
group by id
having sum(case when DETAIL_CODE ='S' and credit>6 then 1 else 2 end)>1
) as t2
on t1.id=t2.id


Madhivanan

Failing to plan is Planning to fail




You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -