try :1.select top 1 from tablename
order by 日期 desc2.select top 1
from tablename a
where tablename. 日期 >a. 日期
order by 日期 desc2.select top 1
from tablename a
where tablename. 日期 >a. 日期
解决方案 »
- 查询SQL中多张表中有几条信息
- 求教一个数据库递规问题
- 简单SQL问题,datepart取日期问题
- 数据库服务器无法访问的问题
- 关于执行计划的解读,聚集索引,in的方式查询
- 求助:SQL Server中和vfp的iif或者oracle的decode具有相似功能的函数是什么?
- 为什么查询分析器的结果和程序中查询结果不一样。
- 请教:SQlserver中有个datetime型字段,想插入日期和时间该怎么写?
- ====咨询在大型企业管理系统开发过程中,数据库方面的视图、存储过程、触发器以及关系如何综合运用?====
- 如何将一个表中的数据原封不动地添加到另一个已存在的同结构的表中?
- 求一句SQL语句的含义!
- windows xp能装sql 2000什么版本
create table #tt (
id varchar (255) null ,
编号 varchar (255) null ,
名称 varchar (255) null ,
价格 varchar (255) null ,
日期 smalldatetime null
)
go--追加测试数据
insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1011' , 'a' , '10.0' , '01 6 2005 11:00pm' )
insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1011' , 'a' , '11.0' , '11 1 2005 11:12pm' )
insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.0' , '09 1 2005 10:05am' )
insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.0' , '10 3 2005 8:06am' )
insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.0' , '11 5 2005 11:09pm' )
insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.1' , '08 1 2004 1:10pm' )
insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.2' , '11 1 2005 11:12pm' )
insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1012' , 'b' , '11.3' , '12 1 2005 9:10pm' )
insert #tt ( id , 编号 , 名称 , 价格 , 日期 ) values ( '001' , '1013' , 'c' , '0.9' , '01 3 2005 6:03am' )--查询结果
select * from #tt a
where not exists (select * from tt where 编号=a.编号 and 日期>a.日期)--删除临时表
drop table #tt
go
create table lsdate
(id nvarchar(5),
bh int,
name nvarchar(5),
price money,
date datetime)
go
insert lsdate
select '001',1011,'a',10.0,'2005-01-06 23:00:00' union all
select '001',1011,'a',11.0,'2005-11-01 23:12:12' union all
select '001',1012,'b',11.0,'2005-09-01 10:05:18' union all
select '001',1012,'b',11.0,'2005-10-03 08:06:00' union all
select '001',1012,'b',11.0,'2005-11-05 23:09:17' union all
select '001',1012,'b',11.1,'2004-08-01 13:10:00' union all
select '001',1012,'b',11.2,'2005-11-01 23:12:12' union all
select '001',1012,'b',11.3,'2005-12-01 21:10:10' union all
select '001',1013,'c', 0.9,'2005-01-03 06:03:11' union all
select '001',1013,'c', 0.7,'2005-11-01 10:28:09'
go
--执行语句
select id,
bh,
name= (select top 1 name from lsdate l where bh = ls.bh and date in (select max(date) from lsdate where name = l.name group by bh) order by date),
price=(select top 1 price from lsdate l where bh = ls.bh and date in (select max(date) from lsdate where name = l.name group by bh) order by date),
date =(select top 1 date from lsdate l where bh = ls.bh and date in (select max(date) from lsdate where name = l.name group by bh) order by date)
from lsdate ls
group by bh,id
go
group by id
from table1
where 日期 = (select max(日期) from table ) group by 编号)
我没有说大家不对
这是我的个子查询我做了是对的大家帮我看下
select * from lsdate where date in(
select max(date) from lsdate
group by id)
where a.id=b.id and a.date=b.date
?
不知道是不是这个意思,你试下select id,max(date) from table_name
group by id