Table UserData (UserID, Sales, Credits)
I need to return the SUM of sales, sum of credits and the # of rows returned for a given date range.
Is it possible in 1 query?
Table UserData (UserID, Sales, Credits)
I need to return the SUM of sales, sum of credits and the # of rows returned for a given date range.
Is it possible in 1 query?
SELECT COUNT(*), SUM(Sales), SUM(Credits)
FROM UserData
WHERE TransactionDate BETWEEN @StartDate AND @EndDate
You can also give names to the computed columns like this
SELECT
COUNT(*) AS NumRows, SUM(Sales) AS SalesTotal, SUM(Credits) AS CreditsTotal
FROM UserData
WHERE TransactionDate BETWEEN @StartDate AND @EndDate