表 tracing 有字段:ID,Type,nextUserID,Date
现要查出 nextUserID = 45,且以Type分类中 Date最大的ID Type NextUserID Date
1 1 45 2006-9-19
2 1 46 2006-9-18
3 2 45 2006-8-1
4 2 46 2006-8-2
5 3 45 2006-7-2
6 3 47 2006-7-1上面查出来的结果应该是
ID Type NextUserID Date
1 1 45 2006-9-19
5 3 45 2006-7-2
现要查出 nextUserID = 45,且以Type分类中 Date最大的ID Type NextUserID Date
1 1 45 2006-9-19
2 1 46 2006-9-18
3 2 45 2006-8-1
4 2 46 2006-8-2
5 3 45 2006-7-2
6 3 47 2006-7-1上面查出来的结果应该是
ID Type NextUserID Date
1 1 45 2006-9-19
5 3 45 2006-7-2
解决方案 »
- SQLserver 中游标while循环中的continue在oracle中怎么用
- 用sqlplus怎样把数据导到excel表格中去?
- 请教 Oracle 事务提交问题
- 在plsql中执行一个sql语句,视图查询 耗时1秒左右,但是在程序中 使用Criteria 分页查询 需要耗时80多秒,求指教,,,,
- 存储过程中,怎样实现插入一个不定长的结构数组?
- 关于oracle监听器的问题
- 请问怎么具体实现oracle数据表中字段值的自增
- 英文的2000,现在冲ORACLE里读出的中文是乱码!请问是什么问题?
- sqlplus work sheet登陆成功了,显示connected,但是sql语句执行不显示结果是怎么回事?
- Orcale9i,把密码忘了,该怎么办呀?
- 请高手指点select count(*)的问题
- 能用一句sql写出来嘛?
from tracing t
where t.nextUserID = 45
group by t.type
按你的方法会查处下面结果
但是 第二条是不对的
ID Type NextUserID Date
1 1 45 2006-9-19
3 2 45 2006-8-1
5 3 45 2006-7-2
from tracing a,(
select t.type,max(Date) maxDate
from tracing t
where t.nextUserID = 45
group by t.type
) tt
where a..nextUserID = 45 and a.type=tt.type and a.Date=tt.maxDate
做的也是出来跟上面同样的结果
ID Type NextUserID Date
1 1 45 2006-9-19
3 2 45 2006-8-1
5 3 45 2006-7-2
nextUserID = 45,且以Type分类为2
Date最大的
select a.*
from tracing a,(
select t.type,max(Date) maxDate
from tracing t
group by t.type
) tt
where a..nextUserID = 45 and a.type=tt.type and a.Date=tt.maxDate感谢wiler(@_@) !! 给分!!!!!!