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
 sql query

Author  Topic 

Ruther
Starting Member

1 Post

Posted - 2007-01-08 : 12:28:27
Hi,
I have a table with data like

dist | school | score
------------------------
100 | sch1 | Pass
------------------------
100 | sch2 | Fail
------------------------
101 | sch11 | Pass
------------------------
101 | sch123 | Fail
------------------------
103 | sch21 | Pass

My problem is
I want to write a query which should result like
for example a dist can have no of school's if any of the school's
score is fail then entire dist score should be displayed as fail


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-08 : 12:34:27
[code]-- prepare sample data
declare @t table (dist int, school varchar(10), score varchar(10))

insert @t
select 100, 'sch1', 'Pass' union all
select 100, 'sch2', 'Fail' union all
select 101, 'sch11', 'Pass' union all
select 101, 'sch123', 'Fail' union all
select 103, 'sch21', 'Pass'

-- show the result
select dist,
min(score) score
from @t
group by dist
order by dist[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -