[Solved] Average within dynamic daterange

Creating tables and queries
Post Reply
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

[Solved] Average within dynamic daterange

Post by gkick »

Hi there,

I need to calculate an average of records for a dynamic date range that is I need to filter dates from today + 90 days, then do a standard between start and finish followed by using the average function
How do I get the end date x+90 into the query - storing the datediff result to a variable or is there some other way.

Thanks
Last edited by gkick on Sat Aug 22, 2020 4:20 pm, edited 1 time in total.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Average within dynamic daterange

Post by Villeroy »

Use function DATEADD as documented.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Sliderule
Volunteer
Posts: 1279
Joined: Thu Nov 29, 2007 9:46 am

Re: Average within dynamic daterange

Post by Sliderule »

Since you are using HSQL 2.5.1 ( or any other version of HSQL since HSQL 2.X / NOT HSQL 1.8.0.10 - Embedded database HSQL ) . . . you can use the built-in functions, DATEADD as well as CURRENT_DATE .

Additionally:
  1. The database back end ( HSQL 2.X ) can return a date from a VIEW ( for example, with a name of "CUR_DATE_90" ) using:

    Code: Select all

    Select DATEADD('day', 90, CURRENT_DATE ) as "CUR_DATE_90" From "INFORMATION_SCHEMA"."SYSTEM_TABLES" LIMIT 1
  2. As a sub-query in your new Query
I hope this helps, please be sure to let me / us know.

Sliderule

Thanks to add [Solved] in your 1st post Subject (edit button top right) if this issue has been resolved.
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Average within dynamic daterange

Post by gkick »

@Sliderule and @Villeroy

Thank you gentlemen
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
Post Reply