Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select SQL with children of children
Message
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Select SQL with children of children
Divers
Thread ID:
00679178
Message ID:
00679178
Vues:
45
Hello,

I try to do an SQL, summarizing invoices, and summarizing the payments to the invoices. In this example, the payment uses Subscriber ID (naSubId) and sequence (naSequence) and the invoice date (naInvDate) to join.
SELECT	.F. AS naSelect, ;
		CN.naSubId, ;
		CN.naSequence, ;
		CN.naFullName, ;
		CM.naInvDate, ;
		COUNT(CM.naSubId) AS FXCnt, ;
		SUM(CM.NaInvAmt) AS FXSum, ;
		SUM(CH.naPayAmnt) AS FXPaid, ;
		0000000000.00 AS Balance ;
	FROM cuName CN ;
		LEFT OUTER JOIN cuMaster CM ;
		ON CM.naSubId = CN.naSubId ;
		AND CM.NaSequence = CN.naSequence ;
		LEFT OUTER JOIN cuHistory CH ;
		ON CH.naSubId = CN.naSubId ;
		AND CH.naSequence = CN.naSequence ;
	GROUP BY CN.naSubId, CN.naSequence ;
	INTO CURSOR cuImport READWRITE
It happens with this code, that the invoice sum (FXSum) is multiplied by the number of payments for that invoice. I do not know what is the right syntax to get the correct Total of Invoices and the total of payments.
Christian Isberner
Software Consultant
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform