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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query help

Author  Topic 

angel9
Starting Member

10 Posts

Posted - 2009-04-08 : 09:53:00
Please help on the following query:

Exclude students who receive STAF loan and NO PELL 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:02
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
   

- Advertisement -