我在 MYSQL 中有一个表,其中除其他字段外,我有两个字段,一个用于月份(Varchar),一个用于年份(int)。月份字段用于存储月份名称,年份用于存储输入数据的年份。我很困惑如何使用 where 类只显示最大月份和年份的记录。 例如
10 records are there for month January 2013
50 records are there for month February 2013
.
.
.
100 records are there for the month of November 2014 --- (LAST ENTRY)
现在
这里我只想显示 2014 年 11 月的记录。我的代码是以这样的方式编写的,我无法使用选择查询,我必须使用 WHERE CLAUSE 来执行此操作
最佳答案
SELECT *
FROM tablename
WHERE
(year, month) = (SELECT year, month
FROM tablename
ORDER BY
STR_TO_DATE(CONCAT_WS(' ', '01', month, year), '%d %M %Y') DESC
LIMIT 1)
关于mysql - 显示上个月和上一年的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19586226/