ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## period_diff,extract ### 说明 | 函数 | 说明 | | --- | --- | | period_diff(p1,p2) | 返回周期p1和p2之间的月数,p1和p2格式为YYMM或YYYYMM | | extract(unit FROM date) | 函数用于返回日期/时间的单独部分 | ### 例子:查询宝宝月龄 ```sql SELECT id, baby_name, baby_birthday, period_diff( extract(YEAR_MONTH FROM curdate()), extract(YEAR_MONTH FROM baby_birthday) ) AS baby_monthage FROM baby; ``` ***** ### 附录 #### extract函数中unit的值 | Unit 值 | | --- | | MICROSECOND | | SECOND | | MINUTE | | HOUR | | DAY | | WEEK | | MONTH | | QUARTER | | YEAR | | SECOND\_MICROSECOND | | MINUTE\_MICROSECOND | | MINUTE\_SECOND | | HOUR\_MICROSECOND | | HOUR\_SECOND | | HOUR\_MINUTE | | DAY\_MICROSECOND | | DAY\_SECOND | | DAY\_MINUTE | | DAY\_HOUR | | YEAR\_MONTH |