0

How select records from related table not older then 3 months

Hello!

Actually the subject says it all.

I searched for a similiar question here, but did not find...

 

In table Treatments i need to have an average cost of a product i bought in a period (lets say 3 months).
Bought product prices are in table Orders.

More or less i understand that i have to SELECT records whose date is not older than 3 months from TODAY().
The only idea i came to, is i need a timestamp of three months to subtract from today's timestamp.

If  there is a more "human" way to do that, please share!!  )) 

Thanks in advance!

Agassi

8 replies

null
    • Agassi
    • 4 yrs agoSat, May 9, 2020 at 7:50 PM UTC
    • Reported - view

    Also ill appreciate a tip how to select top N records sorting DESC by Id.

    • Nick
    • 4 yrs agoSun, May 10, 2020 at 6:20 AM UTC
    • Reported - view

    Hi,

    something like this?

    ---

    let p := Product;
    let d := today() - 180;
    avg((select Order where Product = p and Date >= d).Price)

    ---

    • Agassi
    • 4 yrs agoTue, May 12, 2020 at 9:55 PM UTC
    • Reported - view

    Nickie, thank you very much for your answer!

    And sorry for writing so late. 

     

    Do you know how to select top 10 records when sorting DESC by Id? Something like LIMIT 10?

    • Agassi
    • 4 yrs agoThu, May 14, 2020 at 9:36 AM UTC
    • Reported - view

    Thank You Nick very much for the links!!

    Sorry for "Nickie" in my other post, the phone autocorrected it i guess  ).

    • Nick
    • 4 yrs agoThu, May 14, 2020 at 9:39 AM UTC
    • Reported - view

    Crap... and I thought you loved me!

    lol

    • Ninox partner
    • RoSoft_Steven.1
    • 4 yrs agoThu, May 14, 2020 at 10:16 AM UTC
    • Reported - view

    😂

    • Agassi
    • 4 yrs agoFri, May 15, 2020 at 10:20 AM UTC
    • Reported - view

    Nickie, my dear  )),

    my love and gratitude are limitless ;) jeje