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 2000 Forums
 Transact-SQL (2000)
 Change display format

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-01-06 : 17:10:02
I have a table looks like:

Test Range Score
Math High 89
Matc Low 16
English High 96
English Low 33


I‘m trying to write a query that return the result looks like:

Test High Low
Math 89 16
English 96 33


How can I accomplish this?




tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-06 : 17:13:59
[code]

CREATE TABLE Table1 (Test varchar(10), Score int)

INSERT INTO Table1 VALUES('Math', 89)
INSERT INTO Table1 VALUES('Math', 16)
INSERT INTO Table1 VALUES('English', 96)
INSERT INTO Table1 VALUES('English', 33)

SELECT
Test,
High = (SELECT MAX(Score) FROM Table1 WHERE Test = t.Test),
[Low] = (SELECT MIN(Score) FROM Table1 WHERE Test = t.Test)
FROM Table1 t
GROUP BY Test
ORDER BY Test DESC

DROP TABLE Table1

[/code]

Tara
Go to Top of Page
   

- Advertisement -