I'm prepping for an upcoming test. This is one of the questions
---------------------------------------------------------------------------------------------------
You are a database developer for your company. You are responsible for a Microsoft SQL Server 2005 database named VolunteerGroupData. Your company uses the database to track the volunteer groups that run concession stands during events at a sports stadium.
The database contains a table named GroupPayments that you use to record the amount of money paid to a group for an event. The table contains four columns:
* EventDate - a user-defined data type value to record the date of each event
* StandNum - a tinyint value to record the number assigned to each concession stand
* GroupNum - a smallint value to record the number assigned to each group
* Payment - a money value to record the amount of money earned by a group for an event
An employee plans to feature the three groups that earned the most money during July, 2005, in an article she is writing for a newsletter.
You need to use GroupPayments to determine which three groups she should feature in the article. Your solution should optimize query performance.
Which statement or statements should you use?
SET ROWCOUNT 3;
SELECT GroupNum, SUM (Payment) AS GroupTot
FROM GroupPayments
WHERE EventDate BETWEEN 'July 1, 2005' AND 'August 1, 2005'
GROUP BY GroupNum
ORDER BY GroupTot;
SET ROWCOUNT 3;
SELECT GroupNum, SUM (Payment) AS GroupTot, EventDate
FROM GroupPayments
WHERE EventDate BETWEEN 'July 1, 2005' AND 'July 31, 2005'
GROUP BY GroupNum
ORDER BY GroupTot;
SELECT TOP (3) GroupNum, SUM (Payment) AS GroupTot
FROM GroupPayments
WHERE EventDate BETWEEN 'July 1, 2005' AND 'July 31, 2005'
GROUP BY GroupNum
ORDER BY GroupTot DESC;
SELECT TOP (3) GroupNum, SUM (Payment) AS GroupTot, EventDate
FROM GroupPayments
WHERE EventDate BETWEEN 'July 1, 2005' AND 'August 1, 2005'
GROUP BY GroupNum
ORDER BY GroupTot;
---------------------------------------------------------------------------------------------------------------------------------
I'll post some others later.