表UserData(UserID,Sales,Credits)
我需要返回销售额,信用额和给定日期范围内返回的行数。
1次查询是否可以?
答案 0 :(得分:6)
SELECT COUNT(*), SUM(Sales), SUM(Credits)
FROM UserData
WHERE TransactionDate BETWEEN @StartDate AND @EndDate
答案 1 :(得分:0)
您还可以为此计算列提供名称
SELECT
COUNT(*) AS NumRows, SUM(Sales) AS SalesTotal, SUM(Credits) AS CreditsTotal
FROM UserData
WHERE TransactionDate BETWEEN @StartDate AND @EndDate