SPL simplified SQL case description: interline calculation
In the development of database applications, we often have to face complex SQL computing, and inter-row computing is one of them. For example: divide the monthly sales by the sales of the previous month, compare the previous period, or divide the monthly sales by the sales of the same month last year, and compare the same period. Some database systems do not provide SQL2003 standard window functions, or do not support them completely, so it is necessary to change the way of thinking to complete the interline calculation and use join operation instead, which is not only difficult to understand but also inefficient. Even if you can use window functions, you still have to face problems such as nested subqueries, and SQL statements are still complex and lengthy. On the other hand, SPL can implement interline calculation through simpler and intuitive code, which is illustrated by an example below.
Table sales stores order data for many years, some of which are as follows:
OrderIDClientSellerIdOrderDateAmount10248VINET52013/7/4244010249TOMSP62013/7/51863.410250HANAR42013/7/8181310251VICTE32013/7/8670.810252SUPRD42013/7/9373010253HANAR32013/7/101444.810254CHOPS52013/7/11625.210255RICSU92013/7/122490.510256WELLI32013/7/15517.8 now requires that the sales volume of each month within a specified period of time be calculated according to this table.
SPL Code:
A1=db.query ("select * from sales where ORDERDATE > =? and ORDERDATE"