0

Good day sir..

I was trying to find transactions that are not balance..

so I tried running my query

select transCode,sum(debit) as debitx, sum(credit) as creditx, 
sum(credit-debit)as total 
from x_general_transactions_details 
where total != 0
 group by transCode

but above code doesnt work since you cannot use alias on where so I tried using a variable

select transCode,sum(debit) as debitx, sum(credit) as creditx, 
@total := sum(credit-debit) as total 
from x_general_transactions_details 
where @total != 0
group by transCode

this query doesnt give me an error but doesnt give me a result as well, could you please pin point whats wrong with this query?

the goal of this query is just to find which @total is not equal to 0 which means its not balance..

Thank you very much and have a nice day..

1 Answer 1

1

This is a job for HAVING ...

select transCode,sum(debit) as debitx, sum(credit) as creditx, 
       sum(credit-debit)as total 
  from x_general_transactions_details 
 group by transCode
having sum(credit-debit) != 0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.