
December 7th, 2003, 04:46 PM
|
|
Junior Member
|
|
Join Date: Nov 2003
Location: Vancouver, WA
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Finding TOP 1 of TOP 2
I am trying to find the second most popular item color. I am able with the inner query find the TOP 2, but I have not been able to figure out how to formulate the outer query to isolate the second entry. Any suggestions?
SELECT TOP 1 itemcolor
FROM qitem
WHERE itemcolor IN (
SELECT TOP 2 itemcolor, SUM(saleqty)
FROM qitem, qsale
WHERE qitem.itemname=qsale.itemname
and itemcolor <> '-'
GROUP BY itemcolor
order by SUM(saleqty)desc)
Group By itemcolor
order by itemcolor asc
|