62,266
社区成员
发帖
与我相关
我的任务
分享select convert(varchar(12),c,23),max(a) as zd,px from (
select *,
case when datepart(hour,c)<12 then '上午' else '下午' end as px
from t) as s group by convert(varchar(12),s.c,23),s.px
declare @t table ([id] int, a int, b int, c datetime)
insert into @t
select 1401,144,137,'2009-11-17 08:37:38.000' union all
select 901,142,140,'2009-11-17 09:37:38.000' union all
select 1110,128,125,'2009-11-17 19:19:45.000' union all
select 610,126,128,'2009-11-17 20:19:45.000'
select * from @t t
where exists(select 1 from
(select max(id) as id from @t
group by case when convert(char(10), c, 114)<= '12:00:00:0000' then 'a' else 'b' end
) t1 where t.id=t1.id)
select max(a) from table where Convert(varchar(2),datepart(hour,[时间])) <=12
union all
select max(a) from table where Convert(varchar(2),datepart(hour,[时间])) >=12 and Convert(varchar(2),datepart(hour,[时间])) <=24
select max(a) from table where Convert(varchar(2),datepart(hour,[时间])) <=12
select max(a) from table where Convert(varchar(2),datepart(hour,[时间])) >=12