Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best SQL statement
Message
De
09/09/2007 12:19:39
Reza Meamar
Homa Programming Group
Shiraz, Iran
 
 
À
09/09/2007 04:10:21
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 7 SP1
Divers
Thread ID:
01253272
Message ID:
01253289
Vues:
19
>Hi,
>Try
>
SELECT fldtrue, SUM(fldsum) FROM table GROUP BY fldcode,fldtrue WHERE fldtrue;
>UNION ;
>SELECT .F.,SUM(fldsum) FROM table WHERE !fldtrue
>
>
>>I have a table with below record:
>>
>>FldCode   FldTrue   FldSum
>>  21         T      10000
>>  21         T      20000
>>  22         T      30000
>>  23         F      40000
>>  24         F      50000
>>
>>I want to write a SQL statment that return below result:
>>
>>FldCode   FldTrue   FldSum
>>             T      30000
>>             T      30000
>>             F      90000
>>
>>( I want Sum of similar FldCode and so Sum of records that FldTrue = .F. )
>>
>>Thanks

I made an example cursor for testing your code.
CREATE CURSOR Table1 (FldCode N(2,0), FldTrue L, FldSum N(9,0))
INSERT INTO Table1 VALUES (21,.T.,10000)
INSERT INTO Table1 VALUES (21,.T.,20000)
INSERT INTO Table1 VALUES (22,.T.,30000)
INSERT INTO Table1 VALUES (23,.F.,40000)
INSERT INTO Table1 VALUES (24,.F.,50000)

SELECT fldtrue, SUM(fldsum) FROM table1 GROUP BY fldcode,fldtrue WHERE fldtrue;
UNION ;
SELECT .F.,SUM(fldsum) FROM table1 WHERE !fldtrue INTO CURSOR MyCursor
but it return:
FldTrue   Sum_SumFld
  F         90000
  T         30000
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform