首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql中怎么查询某年某月的数据

2012-03-04 
mysql中如何查询某年某月的数据如题。。假设数据表为|note|CREATETABLE`note`(`id`int(11)NOTNULLauto_incre

mysql中如何查询某年某月的数据
如题。。

假设数据表为
|   note     |   CREATE   TABLE   `note`   (
    `id`   int(11)   NOT   NULL   auto_increment,
    `pid`   int(11)   default   NULL,
    `title`   varchar(100)   default   NULL,
    `content`   varchar(1000)   default   NULL,
    `time`   date   default   NULL,
    `level`   char(1)   default   NULL,
    PRIMARY   KEY     (`id`)
)   ENGINE=InnoDB   DEFAULT   CHARSET=latin1   |

如何根据time字段查出2007年5月的数据

[解决办法]
select * from note where date_format(time, '%Y%m ')= '200705 '
[解决办法]
select * from note where strcmp(date_format(time, '%Y-%m '), '2007-05 ') = 0;

热点排行