Microsoft
Software
Hardware
Network
Question : SQL - For Each statement?
StoreID Score Date Area
002884 83 2008-06-19 00:00:00.000 4002756
002884 50 2008-04-22 00:00:00.000 4002756
002884 70 2007-12-20 00:00:00.000 4002756
002884 76 2007-06-20 00:00:00.000 4002756
002884 64 2007-01-03 00:00:00.000 4002756
002884 80 2006-03-06 00:00:00.000 4002756
002884 76 2005-08-10 00:00:00.000 4002756
002884 64 2004-09-02 00:00:00.000 4002756
007614 71 2008-04-21 00:00:00.000 4002756
007614 80 2007-12-19 00:00:00.000 4002756
007614 76 2007-07-30 00:00:00.000 4002756
007614 80 2007-01-04 00:00:00.000 4002756
007614 75 2006-12-06 00:00:00.000 4002756
007614 66 2006-08-29 00:00:00.000 4002756
007614 68 2006-04-09 00:00:00.000 4002756
007614 83 2005-08-31 00:00:00.000 4002756
007614 88 2004-09-24 00:00:00.000 4002756
==========================
==========
==========
==========
==========
===
The above set of data is the result of a query
SELECT StoreID, Score, Date, Area
FROM Structure
WHERE Area IN ('4002756')
ORDER BY StoreID, Date DESC
As can be seen, this is a listing of all the scores of the different restaurants in a particular region.
The following SQL returns only the Store IDs of the set of data.
SELECT DISTINCT StoreID
FROM Structure
WHERE RptOperID IN ('4002756')
StoreID
002884
007614
In this case there are only two stores.
I need to run a query that will return the top 6 results for each restaurant for the data at the top. Is there a 'for each' type of command? Or how else would be the best way to accomplish this?
Answer : SQL - For Each statement?
something like this:
select * from
(
select ranking = ranking = dense_rank() over (partition by storeid order by score desc), *
from structure
) a
where ranking <= 6
Random Solutions
Always Displaying The Last Text In A Scrolling Text Box
VBA Export Table to CSV file
Stop sysprep from running on boot
Dropdown of Word 2003, Insert Autotext subfolders are all empty
Update a column from another table colum
How do I access another column of data in a ComboBox?
Remote Desktop- blank screen
Receive Connector for Exchange 2007 Server to Receive From Barracuda FW 300
Export 4 Queries to the same Worksheet
-2147467259 [Microsoft][ODBC SQL Server Driver][DBNETLIB]Connectio<wbr />nWrite(Wra<wbr />pperWrite(<wbr />))