34,837
社区成员




select a_id,count(distinct checkdate) 天数 from tt_a group by a_id
create table A(a_id int, checkdate varchar(10) , checktime varchar(10) )
insert into A values(1, '2008-02-01', '08:00:00')
insert into A values(1, '2008-02-01', '17:00:00')
insert into A values(1, '2008-02-03', '08:00:00')
insert into A values(1, '2008-02-03', '13:00:00')
insert into A values(1, '2008-02-03', '17:00:00')
insert into A values(1, '2008-02-04', '17:00:00')
insert into A values(2, '2008-02-11', '08:00:00')
insert into A values(2, '2008-02-11', '17:00:00')
insert into A values(2, '2008-02-13', '08:00:00')
insert into A values(3, '2008-02-23', '13:00:00')
insert into A values(4, '2008-02-03', '17:00:00')
insert into A values(4, '2008-02-04', '17:00:00')
go
select a_id , count(distinct checkdate) 天数 from A group by a_id order by a_id
/*
a_id 天数
----------- -----------
1 3
2 2
3 1
4 2
(所影响的行数为 4 行)
*/
select a_id , count(*) 天数 from (select distinct a_id , checkdate from A) t group by a_id order by a_id
/*
a_id 天数
----------- -----------
1 3
2 2
3 1
4 2
(所影响的行数为 4 行)
*/
drop table A
select a_id, count(distinct convert(varchar(10),checkdate,120)) from a
group by a_id
select a_id , count(*) 天数 from (select distinct a_id , checkdate from a) t group by a_id