SELECT art_id, art_pdate
FROM ecos_article
WHERE art_id>75 limit 0,1
UNION
SELECT art_id, art_pdate
FROM ecos_article
WHERE art_id<=75 ORDER BY art_id DESC limit 0,3
效果如下:
mysql>SELECT art_id, art_pdate FROM ecos_article limit 0,5
+--------+------------+
| art_id | art_pdate |
+--------+------------+
| 73 | 2005-12-01 |
| 74 | 2005-12-01 |
| 75 | 2005-12-01 |
| 76 | 2005-12-01 |
| 77 | 2005-12-01 |
+--------+------------+
mysql>SELECT art_id, art_pdate
->FROM ecos_article
->WHERE art_id>75 limit 0,1
->UNION
->SELECT art_id, art_pdate
->FROM ecos_article
->WHERE art_id<=75 ORDER BY art_id DESC limit 0,3
+--------+------------+
| art_id | art_pdate |
+--------+------------+
| 76 | 2005-12-01 |
| 75 | 2005-12-01 |
| 74 | 2005-12-01 |
+--------+------------+
两个函数的套用,一个是date_add这个函数可以求出当前日期所在月份的第一天的日期,第二个函数是dayname,这个可以返回星期的名字,将dayname套在date_add的外面就可以了。当然不想这么做也可以,将输入的日期转换为字符,然后将后面的日期部分替换成01,然后再用dayname也可以。
date_add求日期坐在月份的第一天
date_add('写入日期',interval -day('写入日期')+1 day),然后再套一层dayname函数就可以了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)