|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
Code:
SELECT TOP 1 itemcolor FROM ( SELECT TOP 2 itemcolor, SUM(saleqty) as x FROM qitem, qsale WHERE qitem.itemname=qsale.itemname and itemcolor <> '-' GROUP BY itemcolor order by x desc) dt order by x asc |
|
#3
|
|||
|
|||
|
Thanks swampBoogie, just what I needed...
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Finding TOP 1 of TOP 2 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|