This is something i have been thinking for hours and still cant get the answer.
Suppose I have this table: table
+---------------------------------------------+
+ date | id | Country | Impressions +
+---------------------------------------------+
+ 2017-03-08 | 1 | US | 374 +
+ 2017-03-09 | 1 | US | 521 +
+ 2017-03-10 | 1 | US | 708 +
+ 2017-03-08 | 2 | US | 100 +
+ 2017-03-09 | 2 | US | 200 +
+---------------------------------------------+
I want to group the results by id and country, but getting the impressions on the last day (max value of date or last record)
I have this query
SELECT * from table group by id,country
but it gives me this output
+---------------------------------------------+
+ date | id | Country | Impressions +
+---------------------------------------------+
+ 2017-03-08 | 1 | US | 374 +
+ 2017-03-08 | 2 | US | 100 +
+---------------------------------------------+
As you can see the date is the first record.
I want a query that gives me this output
+---------------------------------------------+
+ date | id | Country | Impressions +
+---------------------------------------------+
+ 2017-03-10 | 1 | US | 708 +
+ 2017-03-09 | 2 | US | 200 +
+---------------------------------------------+
As you can see the output has the maximum value on date, or last record inserted
I hope you guys can help me on this, i have been burning my head the last hours and failed to get this done.
Thank you very much in advance.