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
How to change @@servername?
How can "duplicate key" errors be handled easily?
Using VBA to transfer CSV in AC07
Remote Web Workplace does not work outside the LAN
How do I set up Exchange 2007 Activesync to work with PDAs that can sync to Exchange Server
How do I Recover/ Repair a "Messed Up" Main Switchboard
Any free software for getting stats reports from Print servers.
Is there a cmd to see active sessions in SQL 2005?
jucheck.exe on windows 7
Delete a subkey