oracle SQL语句筛选出符合条件的数据

有一表数据如下
ID 日期 金额
1 20161231 100
1 20151231 80
1 20141231 90
2 20151231 59
2 20141231 69
2 20131231 50
3 20151231 90
3 20141231 79
3 20131231 89
3 20121231 60
3 20111231 56
从表中筛选出同一个ID中今年的金额比去年多的数据

5个回答

select * from tablename as a inner join tablename as b on a.id = b.id where a.date > b.date and a.mony > b.mony;
没测试过不知道行不行,两个tablename你都改成这张表的名称

SELECT * FROM T T1 WHERE id in (SELECT id FROM T WHERE id=T1.id AND num<T1.num and YEAR(T1.date)-YEAR(date)='1');

select * from tablename as a inner join tablename as b on a.id = b.id where a.date > b.date and a.mony > b.mony;试试看

select * from table1 as a1 left join table as a2 where a1.date>a2.date and a1.money>a2.money

已经解决了,谢谢各位

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐