I have a problem with the SQL query to MySQL: I need to add one field, and for the other to display the last value. Table:
name date interested made_call andrew.h 2011-02-04 10 10 andrew.h 2011-02-11 20 10 andrew.h 2011-02-13 2 10 sasha.g 2011-02-11 5 20 sasha.g 2011-02-12 5 1
This is what I need as a result:
name date interested made_call andrew.h 2011-02-13 2 30 sasha.g 2011-02-12 5 21
I tried to write such a request
SELECT a.name,a.date,a.interested,sum(made_call) as made_call FROM `resultboard` a WHERE a.attendence = 1 AND NOT EXISTS (select 1 from resultboard where name = a.name and id > a.id and attendence = 1) GROUP BY name
but as a result, nothing was added, but only the last result was output:
andrew.h 2011-02-13 2 10 sasha.g 2011-02-12 5 1