Sql查询返回SUM和匹配查询的行数

时间:2009-05-21 15:55:33

标签: jquery sql-server

表UserData(UserID,Sales,Credits)

我需要返回销售额,信用额和给定日期范围内返回的行数。

1次查询是否可以?

2 个答案:

答案 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