Author |
Topic |
pcock
Starting Member
12 Posts |
Posted - 2008-08-20 : 20:45:24
|
Hi All,I have two tables.table: customer_cashcustomer_id, date_in, date_out, amount_cash100, 2008-08-01 10:38:00, 2008-04-05 10:25:00, 180.40100, 2008-08-04 10:27:00, 2008-06-06 10:40:00, 270.50100, 2008-08-06 10:44:00, 2008-08-08 10:39:00, 405.60101, 2008-08-01 10:46:00, 2008-08-08 10:41:00, 0.00table: customer_cardcustomer_id, date_paid, amount_card100, 2008-08-01 11:12:00, 380.40100, 2008-08-03 12:18:00, 88.90100, 2008-08-07 15:01:00, 173.40101, 2008-08-05 15:22:00, 404.35I'd like to write a query summarising customer_cash, but I'd like to sum the amount_card for the date_paid that falls in the customer cash range. The following is a sample output that I like.customer_id, date_in, date_out, amount_cash, amount_card100, 2008-08-01 10:38:00, 2008-04-05 10:25:00, 180.40, 468.90100, 2008-08-04 10:27:00, 2008-06-06 10:40:00, 270.50, 0100, 2008-08-06 10:44:00, 2008-08-08 10:39:00, 405.60, 173.40101, 2008-08-01 10:46:00, 2008-08-08 10:41:00, 0.00, 404.35Thanks. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-21 : 04:11:56
|
[code]SELECT cc.customer_id,cc.date_in,cc.date_out,cc.amount_cash,SUM(ccd.amount_card) AS amount_cardFROM customer_cash cc LEFT JOIN customer_card ccdON ccd.customer_id=cc.customer_idAND ccd.date_paid>=cc.date_inAND ccd.date_paid<=cc.date_outGROUP BY cc.customer_id,cc.date_in,cc.date_out,cc.amount_cash[/code] |
 |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-08-21 : 15:28:33
|
quote: Originally posted by pcock Hi All,I have two tables.table: customer_cashcustomer_id, date_in, date_out, amount_cash100, 2008-08-01 10:38:00, 2008-04-05 10:25:00, 180.40100, 2008-08-04 10:27:00, 2008-06-06 10:40:00, 270.50100, 2008-08-06 10:44:00, 2008-08-08 10:39:00, 405.60101, 2008-08-01 10:46:00, 2008-08-08 10:41:00, 0.00table: customer_cardcustomer_id, date_paid, amount_card100, 2008-08-01 11:12:00, 380.40100, 2008-08-03 12:18:00, 88.90100, 2008-08-07 15:01:00, 173.40101, 2008-08-05 15:22:00, 404.35I'd like to write a query summarising customer_cash, but I'd like to sum the amount_card for the date_paid that falls in the customer cash range. The following is a sample output that I like.customer_id, date_in, date_out, amount_cash, amount_card100, 2008-08-01 10:38:00, 2008-04-05 10:25:00, 180.40, 468.90100, 2008-08-04 10:27:00, 2008-06-06 10:40:00, 270.50, 0100, 2008-08-06 10:44:00, 2008-08-08 10:39:00, 405.60, 173.40101, 2008-08-01 10:46:00, 2008-08-08 10:41:00, 0.00, 404.35Thanks.
This number looks wrong. |
 |
|
pcock
Starting Member
12 Posts |
Posted - 2008-08-21 : 21:58:28
|
Thank you visakh16 for your kind help and yes I did notice the figures were not accurate sodeep |
 |
|
|
|
|