Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group By with Multiple Columns

I have a Table which has following columns.

enter image description here

I want to get results with the same number of columns but with sum of running Balance with Account code not repeating more than once i tried this query

select  AccountCode , 'All Companies' as divisionName , AcName , LF_AccountType , Sum(ISNULL(runningBalance,0)) as  runningBalance  from Table
group by AccountCode , divisionName , AcName , LF_AccountType 
like image 345
Mohammed Asadullah Avatar asked Feb 05 '26 23:02

Mohammed Asadullah


1 Answers

it's unclear what your problem is. However, All columns in the group by statement must be in or derived from the tables queried. So you can't use divisionname in your group by. And you don't need it. So, the immediate syntactic fix would be:

select  AccountCode , 'All Companies' as divisionName , AcName , 
LF_AccountType , Sum(ISNULL(runningBalance,0)) as  runningBalance  
from Table
group by AccountCode, AcName , LF_AccountType
like image 72
Adam Jacobson Avatar answered Feb 09 '26 09:02

Adam Jacobson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!