SELECT mob_no,
(SELECT max(str_to_date(debit_date,'%d/%m/%Y'))
FROM client_debit_bal
WHERE mob_no='".$mobno."') AS date,
sum(debit_amt) AS debit
FROM client_debit_bal
WHERE date_format(str_to_date(debit_date,'%d/%m/%Y'), '%Y-%m-%d')= date
Actually here date
is a alias variable and i cant able to use for condition. Please help me to overcome this problem.
Sample Data's
-----------------------------------
date | cre_amount | mob_no
------------------------------------
23/01/2013 | 100 | 123456
------------------------------------
24/01/2013 | 500 | 123456
------------------------------------
25/01/2013 | 500 | 123456
------------------------------------
26/01/2013 | 900 | 123456
------------------------------------
29/01/2013 | 1000 | 123456
------------------------------------
29/01/2013 | 1300 | 123456
------------------------------------
29/01/2013 | 1200 | 123456
------------------------------------
Expected Output is max(date)
and sum(cre_amount)
and Result is 3500
(Which means select maximum date
and return the sum of cre_amount
from maximum date)