1.写出连续三个月有费用产生的用户
账单表结构:
user_id bill_month amount
20050101 200801 100.32
20050102 200801 60.99
............................ 2. 写出在网日期(使用日期)三个月以上的用户
套餐表结构
user_id apply_date ......
20050101 2008-01-01 ......
20050102 2008-02-01 .......
...............................
解决方案 »
- oracle9i:监听程序无法启动专用服务器进程
- oracle 10g 实现不导入某些表
- 中秋散分!!!!!!!!____顺便问一问题,rowset中插不了行???
- "ORA-00937:非单组分组函数"问题
- 联合查询的问题
- 菜鸟提问:关于根据条件创建表的问题
- oracle10g占用资源的太多,cpu占用从几%到几十%飘忽不定
- 关于ORACLE自动备份的问题(急)
- ORACLE数据转化问题
- SQL语句问题,在线等。
- 執行超長的SQL語句報錯:ORA-00600:內部錯誤代碼,參數:[733],[33803732],[top call heap],[],[],[],[],[]
- 无法从Windows上登录linux下的oracle9i oms server???
(
select user_id,bill_month month1,amount,
lead(bill_month,1) over (order by user_id,bill_month) month2,
lead(bill_month,2) over (order by user_id,bill_month) month3,
lead(user_id,1) over (order by user_id,bill_month) user_id_2,
lead(user_id,2) over (order by user_id,bill_month) user_id_3,
from tablename
) t where user_id=user_id_2 and user_id=user_id_3 and
addmonth(month1,1)=month2 and addmonth(month1,2)=month3;这个思想可以实现,后面判断月份的条件 得根据你的bill_month类型修改下;
from (select t.user_id,
row_number over(partition by t.user_id order by t.bill_month desc) amount_cnt
from table_name t
where amount > 0) a
where amount_cnt >= 3