I have this table calls
id | clientid | salespersonid | duration | statusid | last_update
1 | c11 | sp99 | 05:00 | 1 | yyyy
2 | c11 | sp99 | 06:00 | 1 | yyyy
3 | c11 | sp99 | 07:00 | 3 | yyyy
4 | c12 | sp99 | 08:00 | 3 | yyyy
I'm performing this query to count the number of calls per client for each salesperson
select *,count(wpc.id) as num_of_calls
from calls wpc
where wpc.salespersonid=?
group by wpc.clientid
order by wpc.last_update desc
This returns this result
id | clientid | salespersonid | duration | statusid | last_update|num_of_calls
1 | c11 | sp99 | 05:00 | 1 | yyyy |3
4 | c12 | sp99 | 08:00 | 3 | yyyy |1
The query is fine but I'm not satisfied with the order in which the program counts and displays the rows. It displays the first row of the count. I'm wanting it to display the last row of each count.
So the result should be
id | clientid | salespersonid | duration | statusid | last_update|num_of_calls
3 | c11 | sp99 | 07:00 | 3 | yyyy |3
4 | c12 | sp99 | 08:00 | 3 | yyyy |1
How can I display the last row of each count instead of the first one?