问题
I converted the SQLite line
WHERE strftime('%d%m', orders.created_at) = .......
directly to a MySQL monster:
WHERE CONCAT(CAST(DAY(orders.created_at) AS CHAR), LPAD(CAST(MONTH(orders.created_at) AS CHAR), 2, '0')) = .........
Please, help me to rewrite it to a shorter one.
回答1:
STRFTIME() in SQLite is similar to DATE_FORMAT() in MySQL with reversed parameters.
Since %d
and %m
map to the same thing in both, your expression can simply be written as;
WHERE DATE_FORMAT(orders.created_at, '%d%m') = .......
来源:https://stackoverflow.com/questions/24361074/convert-strftime-in-sqlite-request-to-mysql