oracle-analytics

Duplicating records to fill gap between dates

若如初见. 提交于 2019-11-29 14:40:35
问题 I need to do something really weird, which is to create fake records in a view to fill the gap between posted dates of product prices. Actually, my scenario is a little bit more complicated than that, but I've simplified to products/dates/prices. Let's say we have this table: create table PRICES_TEST ( PRICE_DATE date not null, PRODUCT varchar2(13) not null, PRICE number ); alter table PRICES_TEST add constraint PRICES_TEST_PK primary key (PRICE_DATE, PRODUCT); With these records: insert into

Conditional SUM on Oracle

北战南征 提交于 2019-11-27 06:48:31
问题 I´m tring to make a query with a conditional SUM. The SUM needs to get more than 15, after that reset it. Like this: A | 3 | 3 B | 7 | 10 C | 6 | 16 -- ==== D | 5 | 5 E | 9 | 14 F | 3 | 17 -- ==== G | 8 | 8 How can I make this? 回答1: As an alternative to recursive SQL, you can also use the SQL MODEL clause. Personally, I find this a little easier to read than recursive SQL, though it is harder to write (because most people, like me, need to look up the syntax). -- "test_data" is just a