mysql - SQL sort data based on different columns -


i need sql problem. i'm not sure it's possible do, have table: enter image description here

obtained sql statement:

select distinct account.box, account.name, account.currency, account.lastupdated, account.lastupdatedby, transactions.totals  account left join transactions on account.accountguid = transactions.accountguid 

what end result: enter image description here

so comparing totals each groups of name or currency, obtain highest totals each group. (null values replaced zeroes).

you seem want group by:

select a.box, a.name, a.currency, a.lastupdated, a.lastupdatedby,        max(t.totals) totals account left join      transactions t      on a.accountguid = t.accountguid group a.box, a.name, a.currency, a.lastupdated, a.lastupdatedby; 

note: added table aliases make query easier understand.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -