I have a column name 'AmountLC' in the db table. Another column name 'DebitCredit' determines whether the 'AmountLC' is Positive or Negative. If DebitCredit="H", the values in AmountLC is Negative. If DebitCredit="S", the values in AmountLC is Positive. I need to make query to get the sum of AmountLC. I have tried to get the logic but didn't get any. I would be grateful if anyone can help me.
I tried the below code as per other stackoverflow discussions.
$F7 = mysql_query("SELECT
SUM(CASE WHEN DebitCredit='H' THEN DebitCredit ELSE 0 END) as NegativeTotal,
SUM(CASE WHEN DebitCredit='S' THEN DebitCredit ELSE 0 END) as PostiveTotal
FROM T1_CSV_Table
WHERE Month='$getMonth' AND TaxCode='A0'");
THANKS! Update Code
$F7 = mysql_query("SELECT
SUM(CASE WHEN DebitCredit='H' THEN AmountLC*-1 ELSE AmountLC END) as Total
FROM T1_CSV_Table
WHERE Month='$getMonth' AND TaxCode='A0'");
$rowf7 = mysql_fetch_array($F7);
echo "Total-".$rowf7['Total'];
Update code for results:
SELECT AmountLC
,DebitCredit
FROM T1_CSV_Table
WHERE TaxCode
="A0" AND Month="12"