I have a very simple query:
SELECT a, b, a+b as c FROM records
Which works just fine. He is an example from the results:
Array ( [a] => 100.92 [b] => 21.00 [c] => 121.92 )
But the minute I try to filter records by year:
SELECT a, b, a+b as c FROM records WHERE YEAR(`mydate`) = '2011'
The calculation of a + b disappears:
Array ( [a] => 100.92 [b] => 21.00 [c] => )
Am I missing something obvious?
Update:
I was asked to specify the actual SQL, here it is:
CHOOSE a loan, debit, loan + debit as the final transaction WHERE YEAR ( transaction_date ) = '2011'
A transaction type is a DATE type.
In addition, either the credit or debit field is always zero.
PHP code:
code
include($_SERVER["DOCUMENT_ROOT"] . "/pool/_/db.php"); $sql = "SELECT credit, debit, credit+debit as total FROM transactions WHERE YEAR(`transaction_date`) = 2011"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { print_r($row); }
source share