select * from table where date='2008-12-12' 可否详细说说
select convert( varchar(10),max(date),120) from 表
select convert( varchar(10),cast(max(order_date) as datetime),120) from order_m
select convert(varchar(10),max(时间字段),120) from tableName
假设表中日期字段为 lastdate SELECT * FROM tableName WHERE lastdate=(SELECT CONVERT(varchar(20),max(lastdate),120 ) FROM tableName )
declare @mytime varchar(64) set @mytime='2008-12-12'declare @t table(id int,c1 datetime)insert into @t select '1','2008-12-13' union all select '2','2008-12-26' union all select '3','2008-11-12' union all select '4','2008-10-01' --取近三天内的记录 select * from @t where abs(datediff(day,convert(varchar(10),c1,120),@mytime))<=3
create table test(id int,sql_time datetime)insert test values(1,'2008-12-05') insert test values(2,'2007-11-05') insert test values(3,'2007-10-09') insert test values(4,'2006-11-05') insert test values(5,'2005-10-05')select * from test where sql_time=(select max(sql_time) from test) 如时间字段为CHAR,也一样可以 select * from test where sql_time=(select max(sql_time) from test)
可否详细说说
WHERE lastdate=(SELECT CONVERT(varchar(20),max(lastdate),120 ) FROM tableName )
set @mytime='2008-12-12'declare @t table(id int,c1 datetime)insert into @t
select '1','2008-12-13'
union all
select '2','2008-12-26'
union all
select '3','2008-11-12'
union all
select '4','2008-10-01'
--取近三天内的记录
select * from @t where abs(datediff(day,convert(varchar(10),c1,120),@mytime))<=3
create table test(id int,sql_time datetime)insert test values(1,'2008-12-05')
insert test values(2,'2007-11-05')
insert test values(3,'2007-10-09')
insert test values(4,'2006-11-05')
insert test values(5,'2005-10-05')select * from test where sql_time=(select max(sql_time) from test) 如时间字段为CHAR,也一样可以
select * from test where sql_time=(select max(sql_time) from test)