【问题标题】:In mysql how to use increment i=1, i++?在mysql中如何使用increment i=1, i++?
【发布时间】:2015-02-21 04:54:32
【问题描述】:

<table border='1' cellspacing='0' cellpading='0'>
  <tr>
    <th>Month</th>
     <th>Date</th>
  </tr>
  <tr>
    <th>1st month</th>
     <th>2/12/2014</th>
  </tr>
  <tr>
    <th>2nd month</th>
     <th>2/1/2015</th>
  </tr>
  <tr>
    <th>3rd month</th>
     <th>2/2/2015</th>
  </tr>
  <tr>
    <th>4th month</th>
     <th>2/3/2015</th>
  </tr>
  <tr>
    <th>5th month</th>
     <th>2/4/2015</th>
  </tr>
  <tr>
    <th>6th month</th>
     <th>2/5/2015</th>
  </tr>
<table>

我有用户下面的查询只添加下个月我期望如何在 mysql 中增加一个值?

插入tbl_book(book_date) 值(现在()+ 间隔 1 个月)

我希望对下表进行单个查询

【问题讨论】:

    标签: php mysql sql codeigniter mysqli


    【解决方案1】:

    计划 A:编写带有循环和计数器的存储过程。

    Plan B:创建一个整数表,SELECT from table,在6处停止,在日期算术中使用整数:

    INSERT INTO tbl_book (book_date)
        SELECT CURDATE() + INTERVAL n MONTH
            FROM integers
            WHERE n BETWEEN 1 AND 6;
    

    【讨论】:

    • 不知道存储过程举个例子?
    • 您是在提问和回答吗?希望有人会上钩来重视答案或其他什么? Seems 就像 Lazy Developer 是克隆。这个问题是在第一个问题 90 分钟后放在这里的。
    【解决方案2】:

    使用mysql的dateadd函数。

    DATE_ADD(date,INTERVAL expr type)
    

    您希望间隔为“MONTH”

    INSERT INTO tbl_book(book_date) VALUES (date_add(now( ), INTERVAL 1 Month); 
    

    您可以在http://www.techonthenet.com/mysql/functions/date_add.php找到更多详细信息

    【讨论】:

    • 在插入一行时,我希望在表一上方运行添加 6 行,如表仅使用查询而不是 php
    猜你喜欢
    • 2020-05-24
    • 2012-01-13
    • 2015-08-17
    • 1970-01-01
    • 2014-10-23
    • 2015-05-24
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多