求SQL代码 思路

XJQ_1 2011-03-11 04:19:55
id a b c

1401 144 137 2009-11-17 08:37:38.000
901 142 140 2009-11-17 09:37:38.000
1110 128 125 2009-11-17 19:19:45.000
610 126 128 2009-11-17 20:19:45.000

我想取出0-12点 12点--24点 各自A最大值,结果是

1401 144 137 2009-11-17 08:37:38.000
1110 128 125 2009-11-17 19:19:45.000
...全文
138 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
1楼的也可以吧
主要用max和DataPart
tsltsl2008 2011-03-11
  • 打赏
  • 举报
回复
4楼正解!~~~~~
  • 打赏
  • 举报
回复
解决了啊。我来看下有份接吗。。
广交天下好友 2011-03-11
  • 打赏
  • 举报
回复
4楼代码 正解
小童 2011-03-11
  • 打赏
  • 举报
回复
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
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wxr0323 的回复:]

SQL code
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),……
[/Quote]
+1
mayanly 2011-03-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 airch 的回复:]
0-12的

SQL code

select max(a) from table where Convert(varchar(2),datepart(hour,[时间])) <=12



12-24的+1

SQL code

select max(a) from table where Convert(varchar(2),datepart(hour,[时间])) >……
[/Quote]
wag_enu 2011-03-11
  • 打赏
  • 举报
回复

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)

子夜__ 2011-03-11
  • 打赏
  • 举报
回复
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


Airch 2011-03-11
  • 打赏
  • 举报
回复
如果不取12点的,把等于去掉
Airch 2011-03-11
  • 打赏
  • 举报
回复
0-12的

select max(a) from table where Convert(varchar(2),datepart(hour,[时间])) <=12


12-24的

select max(a) from table where Convert(varchar(2),datepart(hour,[时间])) >=12

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧