SQL Advanced Reports

Hello

I have been trying to create a custom SQL query using Advanced Reports.
I am using the opportunities_audit table which has all changes to an opportunity as events.

I would like to create a range of date validity for a given event, by applying a window function in the code.
This means that for each row (which is an event) I would like to compute lead(date_created) over (partition by parent_id order by date_created).

I could then compute a table with a date dimension (I.e. one column called 'date', with date fields, '2021-01-01', '2021-01-02') and then join that to
the other table on the basis that the date is between the date_created and lead(date_created).

This would give me for a given date in the past, the state of all opportunities in a given point in time.

However, when I try to save the query with this window function, I get a Not Found page.

Could someone help please?
Thanks

Parents Reply
  • mhm, take this as a base select that is working and surprinsingly orders the events in the correct order ascending by time Ö_Ü

    select opa.id, opa.parent_id, opa.event_id, opa.date_created, opa.created_by, opa.date_updated, opa.field_name, opa.data_type, opa.before_value_string, opa.after_value_string, opa.before_value_text, opa.after_value_text from opportunities_audit as opa
     JOIN opportunities as ops on (opa.parent_id = ops.id) order by opa.parent_id, opa.date_created;

    Bests

    Björn

Children
No Data