你们可以为此创造我的智慧。
DELIMITER $$
DROP FUNCTION IF EXISTS `niceDate` $$
CREATE FUNCTION `niceDate` (ts INT) RETURNS VARCHAR(255) NO SQL
BEGIN
declare dt DATETIME;
declare ret VARCHAR(255);
set dt = FROM_UNIXTIME(ts);
IF DATE_FORMAT(dt, "%Y%m%d") = DATE_FORMAT(NOW(), "%Y%m%d") THEN SET ret = Today ;
ELSEIF DATE_FORMAT(dt, "%Y%m%d") = DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 DAY), "%Y%m%d") THEN SET ret = Yesterday ;
ELSE SET ret = CONCAT(DATE_FORMAT(dt, "%M "), DATE_FORMAT(dt, "%d"));
END IF;
RETURN ret;
END $$
DELIMITER ;
You could then construct your query like this:
select niceDate(your_date_field) from table group by niceDate(your_date_field) order by your_date_field desc
否认: i 先检查了这一功能,但你应当了解这一想法。