Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Combine SQL Results into one record
Message
 
 
À
31/07/2013 13:54:07
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01579549
Message ID:
01579551
Vues:
75
This message has been marked as the solution to the initial question of the thread.
>I have the following sql select statement :
>
>
>SELECT  SUM(IIF(division = 'Northern',1,0)) AS NODQTY, SUM(IIF(division = 'Northern',tonnage,0)) AS NODTonnage,;
>      SUM(IIF(division = 'New England',1,0)) AS NEDQTY, SUM(IIF(division = 'New England',tonnage,0)) AS NEDTonnage,;
>      SUM(IIF(division = 'Mid-Atlantic',1,0)) AS MADQTY, SUM(IIF(division = 'Mid-Atlantic',tonnage,0)) AS MADTonnage,;
>      SUM(IIF(division = 'Mid-South',1,0)) AS MSDQTY, SUM(IIF(division = 'Mid-South',tonnage,0)) AS MSDTonnage,;
>      SUM(IIF(division = 'Southern',1,0)) AS SODQTY, SUM(IIF(division = 'Southern',tonnage,0)) AS SODTonnage,;
>      SUM(IIF(division = 'Mid-West',1,0)) AS MWDQTY, SUM(IIF(division = 'Mid-West',tonnage,0)) AS MWDTonnage,;
>      SUM(IIF(division = 'North West',1,0)) AS NWDQTY, SUM(IIF(division = 'North West',tonnage,0)) AS NWDTonnage ;
>FROM curProjects  ;
>INTO CURSOR curTemp WHERE !DELETED() GROUP BY division
>
>
>
>This produces a cursor with something similar to the following:
>
>
>Nodqty  Nodtonnage   Nedqty    Nedtonnage    Madqty   Madtonnage ...
>0           0          0            0         68        25712
>0           0          20           52276      0         0
>143       540593       0            0          0         0
>
>
>
>Is there a way to construct the sql select statement so that I get one line like the following:
>
>
>Nodqty  Nodtonnage   Nedqty    Nedtonnage    Madqty   Madtonnage ...
>143     540593         20        52276        68      25712
>
>
>
>Thanks in advance,

Don't group by Division then to get total amount. You're checking division in all your sum expressions so you obviously don't want to group by Division in addition to that.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform