0

我想要做的是计算更新 2 天的表的行数意味着假设我有一些这样的数据:

ID  Name    Department   DateTime                     ModifyDate
---------------------------------------------------------------------------
1   XXXXX   IT           2013-09-10 09:53:01.000      2013-09-10 09:55:01.000
2   YYYYY   Tech         2013-09-09 10:00:00.000      2013-09-10 12:00:00.000
3   WWWW    IT           2013-09-09 08:09:00.000      2013-09-10 09:09:00.000

现在有两行在 9 月 10 日修改

我想要一个查询,它会给我计数。每天修改行数。

我想要的会是这样

No. of column
    2
4

6 回答 6

1

试试这个

using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (SqlCommand command = new SqlCommand("Select count(ID) from TableName where  ModifyDate>=@Today and ModifyDate<@NextDay", connection))
                {
                    command.Parameters.Add(new SqlParameter("Today",  DateTime.Today  ));
                    command.Parameters.Add(new SqlParameter("Nextday", DateTime.Today.AddDays(1) ));

                    int count = 0;
                    int.TryParse( command.ExecuteScalar().ToString()   , out count);

                }
            }
于 2013-09-11T12:24:06.513 回答
1
select Distinct Count(ID) from Table where ModifyDate between '2013-09-10' and '2013-09-11'
于 2013-09-11T12:31:27.817 回答
1
SELECT COUNT(ID) FROM TableX WHERE ModifyDate BETWEEN @FromDate and @ToDate;

将您的开始和结束日期传递给适当的变量

于 2013-09-11T12:32:33.197 回答
0

你可能想使用类似的东西

SELECT count(ID) 
FROM TableName
GROUP BY CAST(ModifyDate AS DATE)
于 2013-09-11T12:28:18.953 回答
0
select count(*) as [No. of column] from Table1
where CAST(ModifyDate as Date) = 'Sep 10, 2013'

如果要过滤当前日期,请将 'Sep 10, 2013' 替换为 GetDate()。

于 2013-09-11T12:32:29.860 回答
0
SELECT CONVERT(DATE,ModifiedDate) AS DATE, count(ID) AS TotalUpdated
FROM TableName
GROUP BY CONVERT(DATE,ModifiedDate)

试试这个查询。

于 2013-09-11T13:22:27.907 回答