Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Date range in select statement
Message
 
À
04/12/2001 16:08:49
John Deupree
Long Term Care Authority
Tulsa, Oklahoma, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00589506
Message ID:
00589528
Vues:
27
This message has been marked as a message which has helped to the initial question of the thread.
>I have a consumer status table that contains the consumer id, the consumer's status (active, inactive, etc.) and the begin date of the status (the end date is not included - it's assumed that the previous status ended the day the new status began). I would like to determine the date range (or # of days) that a consumer had a certain status. Is there any way to do this with a SQL statement?

You can join the table to itself and calculate the MIN date that's greater than the current date (part of the JOIN condition). That'll give you your two dates. You can't calculate the number of days in the same SQL. You can do that in another view or in the form or report or whatever.

select a.customer_id,;
a.status as beginstatus,;
a.denddate as dbegindate,;
b.status as nextstatus,;
min(b.denddate) as denddate;
from customer_Status a JOIN customer_Status b;
ON a.customer_id=b.customer_id and;
b.denddate>a.denddate;
GROUP BY 1
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform