我遇到查询Mysql的问题,
SELECT orereparto.settimana AS 'Sett', (CASE giorno
WHEN 'lunedi' THEN STR_TO_DATE(orereparto.settimana,'%d,%m,%Y')
WHEN 'martedi' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y') + INTERVAL 1 DAY)
WHEN 'mercoledi' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y') + INTERVAL 2 DAY)
WHEN 'giovedi' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y') + INTERVAL 3 DAY)
WHEN 'venerdi' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y') + INTERVAL 4 DAY)
WHEN 'sabato' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y') + INTERVAL 5 DAY)
WHEN 'domenica' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y') + INTERVAL 6 DAY)
ELSE 0
END) AS 'Giorno', reparti.nomerep AS 'Reparto', SUM(orereparto.orereps) AS 'Ore' FROM orereparto INNER JOIN smk ON orereparto.idsmk = smk.idsmk INNER JOIN reparti ON orereparto.idrep = reparti.idrep WHERE smk.nomesmk = 'Stalingrado' AND orereparto.settimana = '21/07/2014' GROUP BY reparti.nomerep,giorno ORDER BY reparti.nomerep ASC
服务器回答我:
# 1064 - You have an error in your SQL syntax; check the manual That corresponds to your MySQL server version for the right syntax to use near ') WHEN' Wednesday 'THEN DATE_ADD (STR_TO_DATE (orereparto.settimana,'% d,% m,% Y ')' at line 3
答案 0 :(得分:0)
DATE_ADD
在interval
语句之前使用逗号:
SELECT orereparto.settimana AS 'Sett', (CASE giorno
WHEN 'lunedi' THEN STR_TO_DATE(orereparto.settimana,'%d,%m,%Y')
WHEN 'martedi' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y'), INTERVAL 1 DAY)
WHEN 'mercoledi' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y'), INTERVAL 2 DAY)
WHEN 'giovedi' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y'), INTERVAL 3 DAY)
WHEN 'venerdi' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y'), INTERVAL 4 DAY)
WHEN 'sabato' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y'), INTERVAL 5 DAY)
WHEN 'domenica' THEN DATE_ADD(STR_TO_DATE(orereparto.settimana,'%d,%m,%Y'), INTERVAL 6 DAY)
ELSE 0
END) AS 'Giorno', reparti.nomerep AS 'Reparto', SUM(orereparto.orereps) AS 'Ore'
FROM orereparto INNER JOIN
smk
ON orereparto.idsmk = smk.idsmk INNER JOIN
reparti
ON orereparto.idrep = reparti.idrep
WHERE smk.nomesmk = 'Stalingrado' AND orereparto.settimana = '21/07/2014'
GROUP BY reparti.nomerep,giorno
ORDER BY reparti.nomerep ASC;
您还可以通过说:
将intervals
添加到日期
STR_TO_DATE(orereparto.settimana,'%d,%m,%Y') + INTERVAL 1 DAY
但是你混合了两种语法。