MySQL中的常用函数/语句记录

本文最后更新于2016年11月30日,已超过 1 年没有更新,如果文章内容失效,还请反馈给我,谢谢!

=Start=

缘由:

学习需要、提高需要

正文:

MySQL中如何获取上个月的第一天和最后一天
-- http://stackoverflow.com/questions/1138190/mysql-query-to-calculate-the-previous-month

> select DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01');
> select DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%Y-%m-%d');

> select DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01 00:00:00'), DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%Y-%m-%d 23:59:59');
> select DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01'), DATE_FORMAT(NOW() ,'%Y-%m-01');
MySQL中如何获取当前时间、日期、月份、年份、星期几
-- http://stackoverflow.com/questions/2090221/mysql-query-to-get-all-rows-from-previous-month
-- http://stackoverflow.com/questions/9166334/timespan-check-for-weekday-and-time-of-day-in-mysql
-- http://www.manongjc.com/article/109.html

> select now();
> select CURRENT_DATE;
> select MONTH(CURRENT_DATE);
> select YEAR(CURRENT_DATE);
> select DATE_FORMAT(NOW(), '%w'); -- 今天是星期几
MySQL中如何获取一天之前、一个月之前的日期
-- http://stackoverflow.com/questions/7146828/mysql-selecting-yesterdays-date
-- https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

> select subdate(current_date, 1); -- 获取昨天的日期
> select CURDATE() - INTERVAL 1 DAY; -- 获取昨天的日期

> select date_sub(now(), interval 1 month); -- 获取一个月之前的日期
> select date_sub(current_date, interval 1 month); -- 获取一个月之前的日期
待添加

……

=END=

声明: 除非注明,ixyzero.com文章均为原创,转载请以链接形式标明本文地址,谢谢!
https://ixyzero.com/blog/archives/3001.html

3 thoughts on “MySQL中的常用函数/语句记录”

  1. MySQL查询中的OR
    `
    select foo from bar where baz in (1,2,3);

    select foo from bar where baz in (select baz from bar2);

    select foo from bar where baz = ‘1’ or baz = ‘2’ or baz = ‘3’;

    select foo from bar where baz between 1 and 3;
    `
    http://stackoverflow.com/questions/17870/select-where-or
    http://stackoverflow.com/questions/2804881/mysql-question-about-select-where-and-or
    http://stackoverflow.com/questions/6561311/mysql-where-and-or-statement
    https://www.techonthenet.com/mysql/and_or.php
    https://www.techonthenet.com/mysql/or.php

hi进行回复 取消回复

电子邮件地址不会被公开。 必填项已用*标注