我有一个带有用于条目的日期戳字段的 mysql 数据库。我真的很想将年份、季度、月份和日期分成单独的列。我可以毫无问题地创建新列,但我不知道如何编写一个轻松完成此操作的查询。我一直在玩这样的事情
SELECT MONTH();
FROM `datestamp`
但是一直没有快乐...
感激地收到任何帮助:-)
这应该让你开始......
SELECT DAY(`datestamp`) AS `day`,
MONTH(`datestamp`) AS `month`,
YEAR(`datestamp`) AS `year`,
QUARTER(`datestamp`) AS `quarter`
FROM `table`;
这应该有效:
SELECT MONTH(`datestamp`) AS `datemonth`,
DAY(`datestamp`) AS `dateday`,
YEAR(`datestamp`) AS `dateyear`,
QUARTER(`datestamp`) AS `datequarter`
FROM `table`;