I have the following table;
+----+--------------+------------+--------+
| id | wtn          | dueDate    | ageAmt |
+----+--------------+------------+--------+
|  1 | 210-212-3871 | 2001-12-01 |   0.51 |
|  2 | 210-212-3871 | 2001-12-01 |   0.49 |
|  3 | 210-212-3871 | 2001-12-01 |   0.50 |
|  4 | 210-212-3871 | 2002-01-01 |   1.32 |
|  5 | 210-212-3871 | 2002-01-01 |   0.02 |
|  6 | 210-212-3871 | 2002-01-01 |   3.54 |
|  7 | 210-212-3871 | 2002-02-01 |  39.95 |
|  8 | 210-212-3871 | 2002-02-01 |   0.03 |
|  9 | 210-212-3871 | 2002-03-01 |   2.72 |
| 10 | 210-212-3871 | 2002-03-01 |   0.51 |
+----+--------------+------------+--------+

where I would like to query like this;
select wtn,
sum(if(dueDate between 2001-12-01 and 2001-12-30, ageAmt, 0)) AS "+150",
sum(if(dueDate between 2002-01-01 and 2001-01-30, ageAmt, 0)) AS "+120",
sum(if(dueDate between 2002-02-01 and 2001-02-28, ageAmt, 0)) AS "+90",
sum(if(dueDate between 2002-03-01 and 2001-03-30, ageAmt, 0)) AS "+60",
sum(if(dueDate between 2002-04-01 and 2001-04-30, ageAmt, 0)) AS "+30"
from tblAcctRec
group by wtn;

it returns;
+--------------+------+------+------+------+------+
| wtn          | +150 | +120 | +90  | +60  | +30  |
+--------------+------+------+------+------+------+
| 210-212-3871 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
+--------------+------+------+------+------+------+

which is not right. Can anyone see what I'm doing wrong here?

Thanks!

Jay




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to