There is a table with fields id, date, time of a line

1,2016-07-07,11:31:38 2,2016-07-07,11:31:45 3,2016-07-07,11:31:55 5,2016-07-08,10:31:38 6,2016-07-08,12:31:38 

standard query SELECT td.* FROM total td displays everything, but it is necessary when the duplicate date is converted to a null or empty field an example of the answer:

 1,2016-07-07,11:31:38 2,null,11:31:45 3,null,11:31:55 5,2016-07-08,10:31:38 6,null,12:31:38 
  • 2
    It seems to me a strange idea to do this through mysql. make in the code after receiving the answer, before the conclusion (I do not know where it is displayed in you). - Ivan Pshenitsyn

2 answers 2

 SELECT id, CASE WHEN T1.id = T2.min_id THEN T1.date ELSE null END AS date, time FROM total T1 JOIN (SELECT MIN(id) AS min_id, date FROM total GROUP BY date) AS T2 ON T1.date = T2.date; 

SQLFiddle: http://sqlfiddle.com/#!9/e2757/5

    Try this:

     SELECT td.id, IF(@prev_date = date, NULL, @prev_date := date) date, time FROM total td, (SELECT @prev_date := NULL)T ORDER BY id 

    The second line is deciphered like this: If the current date is equal to the previous one, then output NULL, otherwise we display the current date and store it as the previous date for further processing.

    http://sqlfiddle.com/#!9/e2757/6