oracle中如何取时间最晚的那笔数据?
表名:test
表数据如下:
部门 姓名 入职时间
A jack 2010-1-29
A K 2010-1-28
B mike 2010-1-27
B L 2010-1-26
想取出每个部门入职时间最晚的那笔数据该如何取?
结果如下:
部门 姓名 入职时间
A jack 2010-1-29
B mike 2010-1-27
SQL code:
SELECT 部门,姓名, MAX(入职时间) from test GROUP BY 部门,姓名
select * from test t
where not exists(
select 1 from test where 部门=t.部门 and 入职时间>t.入职时间)
SQL code:
select * from test where 入职时间 in
(
select max(入职时间) from test
)
楼上的3位都是正解!
最后一个不对吧。。。。。。
第二个。。可以解释下不,有点看不懂啊。。。
的确是有问题....
SQL code
Code highlighting produced by Actipro CodeHighlight
相关问答:
安装了Oracle 10g,默认安装了orcl数据库,这个数据库能不能删除啊,还有我如果新建了其他数据库,怎么知道在web中登陆不同数据库的地址啊?
1
可以删除
2
在WEB地址栏中输入地址的时候指定新创建的数据库的IP ......
private static final String URL = "jdbc:oracle:thin:@localhost:1521:orcl";
private static final String USERNAME = "sys";
private static final String PASSWORD = "s ......
各位大哥,帮个忙。
下个Oracle for vista 版本的安装试试
10G和11G的
http://www.oracle.com/technology/software/products/database/index.html
------------------------------------------- ......
select sum(a.t)from ta a group by ta.a,这条语句将表ta中的数据按照a字段分组汇总t字段。
结果比如:
3 30
4 50
我想得到这个结果:
1 0
2 0
3 30
4 50
5 0
这个结果,请问sql语句怎么写?多谢
nobody ......
我是在toad中输入下段sql
declare
TYPE test_rec IS record(
code varchar(10),
name varchar(30)
);
v_book test_rec;
......