JAVA程序员求PL/SQL的面试题目,有的朋友贴下,最好是最新的,谢谢了
------解决方案--------------------------------------------------------
问题:
销售表sale中有如下数据,记录了每个月的销售额情况
SQL> select * from sale;
MONTH SELL
------ ------------
200001 1000.00
200002 2000.00
200003 4000.00
200004 66454.00
200005 2344.00
200101 81233.00
200103 441241.00
200210 345441.00
200305 43113.00
9 rows selected
现要得到如下显示数据:
MONTH SUM
------ ----------
200001 1000
200002 3000
200003 7000
200004 73454
200005 75798
200101 157031
200103 598272
200210 943713
200305 986826
即:累加每月销售额。
今天,我初步用了三种方法实现该需求。
第一种:自连接
SQL> select b.month,sum(a.sell) from sale a,sale b
2 where a.month<=b.month
3 group by b.month
4 order by b.month;
第二种:子查询
SQL> select a.month,
2 (select sum(b.sell) from sale b where b.month<=a.month)
3 from sale a;
第三种:利用Oracle8.1.6开始提供的分析函数实现(超简单!)。
SQL> select month,sum(sell)over(order by month) from sale;
或者
SQL> select month,sum(sell)over(order by month rows between unbounded preceding and current row ) from sale;
或者
SQL> select month,sum(sell)over(order by month range unbounded preceding ) from sale;
因为这三个语句是等效的。
------解决方案--------------------------------------------------------
你面试的职位是什么?JAVA程序员吗,如果是的话只要知道PL/SQL存储过程,函数的写法和一些SQL的写法就可以了。