Subject RE: [firebird-support] Firebird SQL query - Average days between dates
Author Alan McDonald
> Firebird 1.5.3
> Delphi 5 Pro
>
> I have a table in a Firebird database (Sales table) that includes a
> CustID and SaleDate field. Is it possible to query this table (with a
> select statement)to get the Average days between saledates for a
> particular customer.
>
> thanks in advance
>
> Bill
>

there may be a straight SQL solution and also a tricky SP solution but I
think a little cleverness at the front end might be in order.
You are posting this saledate for this CustID, it's on that screen that I
would include a simple select result... last sale date or this customer.
Now when you post each and every sale, one field in the sale is last sale.
Now you have CustID, SaleDate, LastSale,
a trigger can just subtract the 2 new. values to store an integer value
(days since last sale) in another field.
Now everytime you want this average days between saledates.
select avg(intfielddiff) from custsales where custid=xx

Alan