求下面查询下面数据的SQL

收获de季节 2010-01-27 04:23:01
如下的数据,请问下怎么写SQL

科目 期间 金额 日期
1009 200903 20 2010/01/02
1009 200903 20 2010/01/27
1009 200903 20 2010/01/26
1009001 200903 20 2009/10/01
1009001 200903 20 2009/12/12
1009002 200903 20 2003/12/32
1009002 200903 20 2010/01/08

取到下面数据
科目 期间 金额 日期
1009 200903 20 2010/01/27
1009001 200903 20 2009/12/12
1009002 200903 20 2010/01/08
...全文
122 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
收获de季节 2010-03-24
  • 打赏
  • 举报
回复
这个我最终选择了,两个字段通过连接进行比较的方法
huangyunzeng2008 2010-01-28
  • 打赏
  • 举报
回复
应该有相应的文字说明来描述你的需求的
w3329307 2010-01-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 acmain_chm 的回复:]
SQL codeselect 科目,期间,金额,max(日期)from table1groupby 科目,期间,金额
[/Quote]
他都是取的第二列???
w3329307 2010-01-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 shiyiwan 的回复:]
select * from t t1 where not exists (select 1 from t t2
where t1.kemu = t2.kemu and t1.qijian = t2.qijian and t1.jine = t2.jine
and t1.riqi < t2.riqi);
[/Quote]
看看,顺便帮顶个
crazylaa 2010-01-27
  • 打赏
  • 举报
回复
shiyiwan和acmain的都可以
  • 打赏
  • 举报
回复
select * from t t1 where not exists (select 1 from t t2 
where t1.kemu = t2.kemu and t1.qijian = t2.qijian and t1.jine = t2.jine
and t1.riqi < t2.riqi);
Tomhahaha1 2010-01-27
  • 打赏
  • 举报
回复
好像不是最大日期哦,还有12月32号? 是不是还要去掉没意义的日期啊?
alice鑫鑫 2010-01-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 shiyiwan 的回复:]
select * from t t1 where not exists (select 1 from t t2
where t1.kemu = t2.kemu and t1.qijian = t2.qijian and t1.jine = t2.jine
and t1.riqi < t2.riqi);
[/Quote]
liusong_china 2010-01-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 acmain_chm 的回复:]
SQL codeselect 科目,期间,金额,max(日期)from table1groupby 科目,期间,金额
[/Quote]

嗯,如果是取最大日期的那条记录就是这样子。。

楼主应该附加一些文字描述的。
ACMAIN_CHM 2010-01-27
  • 打赏
  • 举报
回复
select 科目,期间,金额,max(日期)
from table1
group by 科目,期间,金额
shiyiwan 2010-01-27
  • 打赏
  • 举报
回复
select * from t t1 where not exists (select 1 from t t2
where t1.kemu = t2.kemu and t1.qijian = t2.qijian and t1.jine = t2.jine
and t1.riqi < t2.riqi);

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧