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

Author  Topic 

drpkrupa
Yak Posting Veteran

74 Posts

Posted - 2007-04-13 : 13:08:44
I have a table with three feild
ID, status , accountno
1 2 100
2 1 100
3 1 200
4 1 300
5 2 300

I need result: all record with status 2 but if they pass next time then exclude.

I need result only for accountno 300
for 100 it was fail = 2 but it pass later 1 so exclude

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-13 : 13:11:21
what is the 'pass' limit? is it always 100? So anything above 100 is pass?

SELECT ..
FROM ..
WHERE status =2 and accountno > 100




************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-13 : 13:15:36
[code]SELECT AccountNo
FROM Table1
GROUP BY AccountNo
HAVING MAX(CASE WHEN Status < 2 THEN ID END) < MAX(CASE WHEN Status >= 2 THEN ID END)[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -