时间 名称
2010-1-1 1:22:23 A
2010-1-1 1:23:23 A
2010-1-1 1:23:23 A
2010-1-2 1:22:23 B
2010-1-2 1:22:23 A期望结果为2010-1-1 3
2010-1-2 2感谢您的指教
2010-1-1 1:22:23 A
2010-1-1 1:23:23 A
2010-1-1 1:23:23 A
2010-1-2 1:22:23 B
2010-1-2 1:22:23 A期望结果为2010-1-1 3
2010-1-2 2感谢您的指教
from tb
group by convert(nvarchar(10),时间,120)
group by convert(varchr(10),时间,120)
--> 数据库版本:
--> Microsoft SQL Server 2008 (RTM) - 10.0.1600.22
--> 测试数据:[TB]
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[TB]')
AND type in (N'U'))
DROP TABLE [TB]
GO---->建表
create table [TB]([tt] datetime,[ff] varchar(1))
insert [TB]
select '2010-1-1 1:22:23','A' union all
select '2010-1-1 1:23:23','A' union all
select '2010-1-1 1:23:23','A' union all
select '2010-1-2 1:22:23','B' union all
select '2010-1-2 1:22:23','A'
GO--> 查询结果
SELECT CONVERT(date,tt),COUNT(ff)
FROM [TB]
group by CONVERT(date,tt)
--> 删除表格
--DROP TABLE [TB]
select convert(nvarchar(10),时间,120),count(*)
from 表 group by convert(nvarchar(10),时间,120)
from 表 group by convert(nvarchar(10),时间,120)
insert [TB]
select '2010-1-1 1:22:23','A' union all
select '2010-1-1 1:23:23','A' union all
select '2010-1-1 1:23:23','A' union all
select '2010-1-2 1:22:23','B' union all
select '2010-1-2 1:22:23','A'
GOselect convert(varchar(10),时间,120) 时间 , count(1) 数量 from tb group by convert(varchar(10),时间,120)drop table tb/*
时间 数量
---------- -----------
2010-01-01 3
2010-01-02 2(所影响的行数为 2 行)
*/
from tb
group by convert(nvarchar(10),时间,120)
count(1)
from tb group by convert(varchar(10),时间,120)
create table tab(dt datetime,name varchar(20))
--插入数据
insert into tab values('2010-1-1 1:22:23','A')
insert into tab values('2010-1-1 1:23:23','A')
insert into tab values('2010-1-1 1:23:23','A')
insert into tab values('2010-1-2 1:22:23','A')
insert into tab values('2010-1-2 1:22:23','A')
select * from tab
--SQL 语句
select convert(varchar(10),dt,120) as Testdt,count(*) from tab group by convert(varchar(10),dt,120)