I have a table:
ID ACCOUNT BALANCE TIME
1 Bill 10 1478885000
2 Bill 10 1478885001
3 James 5 1478885002
4 Ann 20 1478885003
5 Ann 15 1478885004
I want to get latest (based on TIME) balance of several accounts. I.e.:
ACCOUNT BALANCE
Bill 10
Ann 15
I try to use this SQL:
SELECT ACCOUNT, BALANCE, max(TIME)
FROM T1
WHERE ACCOUNT IN ( 'Bill', 'Ann')
GROUP BY ACCOUNT
I receive error:
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'BALANCE' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
I understand the error and tried different SQLs but still do not understand how to retrieve needed data without multiple queries.
P.S. I use MySQl 5.7