Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL statement
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01442245
Message ID:
01442247
Vues:
30
>I have a joined query result set that give the result as show in image #1
>
>
>	SELECT O_ord_pay.op_main_key, O_ord_pay.op_ord_date, O_ord_pay.op_desc,;
>  O_ord_pay.op_vendor, O_ord_pay.op_po_no, O_ord_pay.op_amt, Req_payment.r_payamt, r_paiddate;
> FROM ;
>     dbbudget!o_ord_pay ;
>    INNER JOIN dbbudget!req_payment ;
>   ON  O_ord_pay.op_uniqueid = Req_payment.r_id;
> WHERE  O_ord_pay.op_prt_comp = "P"
>
>
>how can I rewrite the query above so that my result shows one line showing the total of r_payment (sum) columns. For example
>
>
>Op_ma        Op_ord_date        Op_desc            Op_vendor       Op_po_no    Op_amt         R_payamt     R_paiddate
>7700         05/29/2009         RANGE TARGETS      SPEEDWELL       098252       3761.20       3436.40      10/14/2009
>7700         05/29/2009         PRACTICE/DUTY      DOOLEY ENT      098302       33581.32      4786.82      11/19/2009
>
>
>
>I would like it to sum R_payment column fo all columns that have the same Op_po_no. I have tried group by but keep getting subscript reference errors. thanks. Nick.

Do you want to show the rest of the R information? If yes, then use derived table, e.g.
SELECT O_ord_pay.op_main_key, O_ord_pay.op_ord_date, O_ord_pay.op_desc,;
  O_ord_pay.op_vendor, O_ord_pay.op_po_no, O_ord_pay.op_amt, Req_payment.r_payamt, r_paiddate;
 FROM ;
     dbbudget!o_ord_pay ;
    INNER JOIN dbbudget!req_payment ;
   ON  O_ord_pay.op_uniqueid = Req_payment.r_id;
   inner join 
(select R1.Orp_Po_No, sum(R_payment) as Total_R_Payment from  dbbudget!req_payment  R1 group by R1.Orp_Po_No) X on
  Req_payment.Orp_Po_No = X.Orp_Po_No
 WHERE  O_ord_pay.op_prt_comp = "P"
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform