Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need SQL to find LATEST child record
Message
 
À
16/04/2003 03:02:35
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00777700
Message ID:
00778299
Vues:
19
>Chad,
>I'm sorry to say that this works because sample data is set to work. Try with this :
>
>SELECT 0
>CREATE CURSOR inmates (cid i, cinmate_number c(7))
>INSERT INTO inmates VALUES (1, '0012345')
>INSERT INTO inmates VALUES (2, '0023456')
>INSERT INTO inmates VALUES (3, '0023458')
>SELECT 0
>CREATE CURSOR acct_events (cid c(2), cinmates_id i, ttxndatetm t, txnstatus c(6))
>INSERT INTO acct_events VALUES ('X1', 1, {^2003-04-01,12:00:00A}, 'OPEN')
>INSERT INTO acct_events VALUES ('X2', 1, {^2003-04-05,04:00:00A}, 'CLOSED')
>INSERT INTO acct_events VALUES ('X3', 1, {^2003-04-05,06:00:00A}, 'OPEN')
>INSERT INTO acct_events VALUES ('X4', 1, {^2003-04-07,12:00:00A}, 'CLOSED')
>INSERT INTO acct_events VALUES ('X5', 2, {^2003-04-01,08:00:00A}, 'OPEN')
>INSERT INTO acct_events VALUES ('X6', 2, {^2003-04-05,04:00:00A}, 'CLOSED')
>INSERT INTO acct_events VALUES ('X7', 2, {^2003-04-05,06:00:00A}, 'CLOSED')
>INSERT INTO acct_events VALUES ('X8', 3, {^2003-04-05,06:00:00A}, 'OPEN')
>
Cetin,

You are correct. When the tTxnDateTm values match, the results are not what is desired. I didn't catch that with the sample data supplied. I guess he could simply concatenate the cInmates_ID field in with the tTxnDateTm to make it unique per inmate since a single inmate wouldn't have two status changes in the same second:
SELECT cInmate_Number, tTxnDateTm, TxnStatus ;
  FROM INMATES im ;
    LEFT JOIN ACCT_EVENTS ae ;
      ON im.cID = ae.cInmates_ID ;
  WHERE TRANSFORM(cInmates_ID) + TTOC(tTxnDateTm, 1) IN ;
    (SELECT MAX(TRANSFORM(cInmates_ID) + TTOC(tTxnDateTm, 1)) FROM ACCT_EVENTS GROUP BY cInmates_ID) ;
    AND TxnStatus = 'OPEN'
_________________________________
There are 2 types of people in the world:
    Those who need closure
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform