Please assist me in combining these sql queries
-
Greetings to you, Please assist me in combining these sql queries I have some record in my database (sql ce 4.0), using; 1.
Select Customer_ID as Customer, Credit, Debit, Transaction_Date as Date
from ThriftsTrans Where Transaction_Date Between '15/Dec/2013' And '18/Dec/2013'Produces this result;
Customer Credit Debit Date
000001 12000 2013-12-16T14:32:00.9770000
000001 5000 2013-12-16T14:32:26.0070000
000001 2000 2013-12-16T14:32:43.3870000
000001 2000 2013-12-17T10:23:08.6470000
000002 50000 2013-12-17T10:25:35.4730000
000002 1000 2013-12-17T10:25:49.4230000
000002 3000 2013-12-17T10:26:07.4800000If i run this; 2.
Select Customer_ID as Customer, sum(Credit) as Credit, sum(Debit) as Debit,
(Sum(Credit)-Sum(Debit)) as Balance, (count(Credit) + count(Debit)) as Count
from ThriftsTrans Where Transaction_Date Between '15/Dec/2013' And '18/Dec/2013' Group By Customer_IDI will get;
Customer Credit Debit Count
000001 19000 2000 4
000002 51000 3000 3and lastly if i run; 3.
Select Customer_ID as Customer, Account_Balance as Balance, Transaction_Date as Date From ThriftsTrans Where Transaction_Date In (Select Max(Transaction_Date) From ThriftsTrans Where Transaction_Date
Between '15/Dec/2013' And '18/Dec/2013' Group By Customer_ID)I will get;
Customer Balance Date
000001 17000 2013-12-17T10:23:08.6470000
000002 48000 2013-12-17T10:26:07.4800000But my problem now, is how do i combine query 2 & query 3 to get the following output from my database;
Customer Credit Debit Count Balance Date
000001 19000 2000 4 17000 2013-12-17T10:23:08.6470000
000002 51000 3000 3 48000 2013-12-17T10:26:07.4800000Please help me and thanks a lot in advance.