1.日期类型datetime或date转为字符串 DATE_FORMAT(date,format)
2.时间戳类型转字符串 FROM_UNIXTIME(unix_timestamp,format)
3.字符串转为日期格式 STR_TO_DATE(str,format)
例如:按月份分组计算今年的每月的营业额
SELECT DATE_FORMAT(set_time,'%m') as months, sum(price) as totalPrice
FROM tb_order
WHERE set_time
BETWEEN str_to_date('2018-01-01 00:00:00', '%Y-%m-%d %H:%i:%s')
AND str_to_date('2019-01-01 00:00:00', '%Y-%m-%d %H:%i:%s')
GROUP BY months