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
  • Hi Ada

    Can you share the sql query you are trying to execute?

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi

    This is the query: select parent_id, event_id, date_created, lead(date_created) over (partition by parent_id order by date_created) from opportunities_audit where parent_id = 'x'

    I am unsure if the MySQL engine supports window functions, so maybe this can't work? 

    Is there any way to leverage subqueries? I.e select * from (select * from opportunities) ?

    Thanks, 
    Ada

Reply
  • Hi

    This is the query: select parent_id, event_id, date_created, lead(date_created) over (partition by parent_id order by date_created) from opportunities_audit where parent_id = 'x'

    I am unsure if the MySQL engine supports window functions, so maybe this can't work? 

    Is there any way to leverage subqueries? I.e select * from (select * from opportunities) ?

    Thanks, 
    Ada

Children