Aggregate function, grouped by non-definining field
Hi guys, I have a simple question. To put this short, I have a table that when I give a query like this:
select a.GroupName, a.In, a.Out, a.Remarks
from {TableName} a
order by a.GroupName, a.In desc, a.Out desc
The result of the query will be like this:
"Group Name" / "IN" / "OUT" / "Remarks"
---------------------------------------
A1 / 10 / 5 / Good morning
A2 / 20 / 20 / Good evening
B1 / 13 / 23 / Good morning
B1 / 2 / 30 / Good day
B2 / 3 / 15 / Good night
B2 / 3 / 13 / Good morning
C1 / 20 / 2 / Good afternoon
If i do something like:
select a.GroupName, sum(a.In), sum(a.Out), a.Remarks
from {TableName} a
group by a.GroupName
order by a.GroupName, sum(a.In) desc, (a.Out) desc
Will the query result ALWAYS be like this:
"Group Name" / "IN" / "OUT" / "Remarks"
---------------------------------------
A1 / 10 / 5 / Good morning
A2 / 20 / 20 / Good evening
B1 / 15 / 53 / Good morning
B2 / 6 / 28 / Good night
C1 / 20 / 2 / Good afternoon
Notice that there are 2 records with the name "B1" and also 2 records with the name "B2". What I want, is to get the "Remarks" of the record with greater "IN" value.
Please let me know if I'm unclear, because I think this is the simplest way I can think of to explain my situation. Any help would be appreciated...