好像很简单,不是我理解错了吧 select A字段, max(时间字段) from your_table group by A字段 如果有条件,自己再加上where就可以了
时间字段(date) 最接近现在时间一批记录??,接近到什么程度撒?
TO 阿宝:我是想把除了A字段外还有几个字段都选出来,如B,C,D,现在只可以选择A字段和最大的时间,请问可以选择出除了A字段以外的B,C,D,字段吗?
可以,不过我想了解你的表结构是什么样子的,主键是什么,又没有可能出现以下情况: A字段, 时间字段, B字段, C字段, D字段 A 2004-06-23 B C D A 2004-06-23 BB CC DD 如果出现这种情况,是2条都选还是只选1条,选那一条?
TO 阿宝:先谢谢您 我的表结构是: A字段,日期字段, 时间字段,B字段,C字段,D字段 编号 A 2004-06-23 10:50 B C D 1 A 2004-06-23 10:51 B1 C1 D1 2 A1 2004-06-23 10:50 B2 C2 D2 3 A1 2004-06-23 10:52 B3 C3 D3 4 我要选的记录是2,4,就是选所有字段
select * from your_table where 时间字段 in select max(时间字段) from your_table group by A字段
select * from your_table where (时间字段 in select max(时间字段) from your_table group by A字段 ) and (A字段 in select A字段 from your_table group by A字段 )
select A字段, 時間字段 from your_table t where 時間字段 = (select max(時間字段) from your_table where t.A字段=A字段) order by A字段
试试 select a.A字段,a.日期字段, a.时间字段,a.B字段,a.C字段,a.D字段, a.编号 from your_table a where a.日期字段 = (select max(日期字段) from your_table where A字段 = a.A字段) and b.时间字段 = (select max(时间字段) from your_table where 日期字段 = a.日期字段) 我的还是觉得把(日期字段+时间字段)进行判断是最快的,都转成字符串再加,再MAX
好的 谢谢我测试出来了, select x0.* from my_table x0 where x0.日期时间一起 in (select max(日期时间一起) from my_table group by A字段)但是怎样用sql把日期和时间连在一起呢?
select A字段, max(时间字段) from your_table group by A字段
如果有条件,自己再加上where就可以了
A字段, 时间字段, B字段, C字段, D字段
A 2004-06-23 B C D
A 2004-06-23 BB CC DD
如果出现这种情况,是2条都选还是只选1条,选那一条?
我的表结构是:
A字段,日期字段, 时间字段,B字段,C字段,D字段 编号
A 2004-06-23 10:50 B C D 1
A 2004-06-23 10:51 B1 C1 D1 2
A1 2004-06-23 10:50 B2 C2 D2 3
A1 2004-06-23 10:52 B3 C3 D3 4
我要选的记录是2,4,就是选所有字段
select max(时间字段) from your_table group by A字段
(时间字段 in select max(时间字段) from your_table group by A字段 )
and
(A字段 in select A字段 from your_table group by A字段 )
from your_table t
where 時間字段 = (select max(時間字段)
from your_table
where t.A字段=A字段)
order by A字段
select a.A字段,a.日期字段, a.时间字段,a.B字段,a.C字段,a.D字段, a.编号
from your_table a
where a.日期字段 = (select max(日期字段) from your_table where A字段 = a.A字段)
and b.时间字段 = (select max(时间字段) from your_table where 日期字段 = a.日期字段)
我的还是觉得把(日期字段+时间字段)进行判断是最快的,都转成字符串再加,再MAX
select x0.*
from my_table x0
where x0.日期时间一起 in (select max(日期时间一起) from my_table group by A字段)但是怎样用sql把日期和时间连在一起呢?