当前位置:数据库 > Access >>

access数据库SQL语句查询问题

如下表 name time col1 col2 col3 A 2009-11-1 * * * B 2009-10-1 * * * A 2009-12-1 * * * C 2009-11-10 * * * B 2009-10-5 * * * 我想通过SQL语句查询出name中各项(不重复项)最近时间(time)的所有信息。查询结果要为: name time col1 col2 col3 A 2009-12-1 * * * B 2009-10-5 * * * C 2009-11-10 * * * 请问SQL语句应该怎么写? 谢谢。
答案:select * from table   T1
INNER JOIN
(
select name,min(time) as time   from table  group by name
) T2
on
t1.name=t2.name
and
t1.time = t2.time
其他:select * from table order by name,time desc 没有解决完全,获取最近时间 不知道怎么判断,其余应该和你要求的一样

这样的只是查询 name中 不重复的项 第一次出现的行
select distinct(name),min(time) as time   from table  group by name select * from 该表名 where exists(select distinct name from 该表名order by time desc)
 

distinct命令 是选非重复项 
order by time desc 按时间排列 

上一个:请给 菜鸟的数据库设计,提提意见,asp+access.......
下一个:如何将sql数据库的表导入到Access数据库中

Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,