答案 0 :(得分:0)
您需要先转换为日期类型(STR_TO_DATE),然后再转换为所需格式的字符串(DATE_FORMAT)
STR_TO_DATE(t.date, '%c/%e/%Y'), DATE_FORMAT(STR_TO_DATE(tdate, '%c/%e/%Y'), '%m/%e/%Y')
答案 1 :(得分:0)
SET @today = CURRENT_DATE(),
@day1 = DATE_ADD(CURRENT_DATE(),INTERVAL -1 DAY),
@day2 = DATE_ADD(CURRENT_DATE(),INTERVAL -2 DAY),
@day3 = DATE_ADD(CURRENT_DATE(),INTERVAL -3 DAY),
@day4 = DATE_ADD(CURRENT_DATE(),INTERVAL -4 DAY),
@day5 = DATE_ADD(CURRENT_DATE(),INTERVAL -5 DAY),
@sql = concat("SELECT JRR_RESULT, COUNT(LEFT(JRR_RESULT,40)) AS 'Total Error
Last
5 Days'"
", sum(IF( DATE_FORMAT(CREATION_DATE,'%Y-%m-%d') = '" , @day1, "',1,0) ) AS
'",
@day1, "' "
", sum(IF( DATE_FORMAT(CREATION_DATE,'%Y-%m-%d') = '" , @day2, "',1,0) ) AS
'",
@day2, "' "
", sum(IF( DATE_FORMAT(CREATION_DATE,'%Y-%m-%d') = '" , @day3, "',1,0) ) AS
'",
@day3, "' "
", sum(IF( DATE_FORMAT(CREATION_DATE,'%Y-%m-%d') = '" , @day4, "',1,0) ) AS
'",
@day4, "' "
", sum(IF( DATE_FORMAT(CREATION_DATE,'%Y-%m-%d') = '" , @day5, "',1,0) ) AS
'",
@day5, "' "
" FROM your_table where DATE_FORMAT(CREATION_DATE,'%Y-%m-%d') >= '" , @day5,
"' "
" Group by LEFT(JRR_RESULT,40)");
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;