SELECT `loanac`.`id`, `loanac`.`area`
FROM loanac, loantrans
WHERE `loanac`.`lacc`=`loantrans`.`account`
GROUP BY `loanac`.`lacc`
HAVING SUM(IFNULL(`loantrans`.`out`,0)) > SUM(IFNULL(`loantrans`.`in`,0))
QUERY RESULT:
----------------------------------------
id area
----------------------------------------
5 A
165 C
166 C
167 C
232 D
91 B
This Query gives me all id & area for lacc's who have out>in, this query is is OK & working, I just need to get output GROUP BY area and COUNT id from this query. Can anyone help?
What I want is
----------------------------------------
COUNT(id) GROUP BY(area)
----------------------------------------
1 A
5 B
9 C
1 D
NOTE: The conditions aren't change Target: Want to find/count number of (loanac.id) grouping by (loanac.area) with same conditions