<legend id='J2RqH'><style id='J2RqH'><dir id='J2RqH'><q id='J2RqH'></q></dir></style></legend>
    <tfoot id='J2RqH'></tfoot>

  1. <small id='J2RqH'></small><noframes id='J2RqH'>

      <bdo id='J2RqH'></bdo><ul id='J2RqH'></ul>
  2. <i id='J2RqH'><tr id='J2RqH'><dt id='J2RqH'><q id='J2RqH'><span id='J2RqH'><b id='J2RqH'><form id='J2RqH'><ins id='J2RqH'></ins><ul id='J2RqH'></ul><sub id='J2RqH'></sub></form><legend id='J2RqH'></legend><bdo id='J2RqH'><pre id='J2RqH'><center id='J2RqH'></center></pre></bdo></b><th id='J2RqH'></th></span></q></dt></tr></i><div id='J2RqH'><tfoot id='J2RqH'></tfoot><dl id='J2RqH'><fieldset id='J2RqH'></fieldset></dl></div>

      MySQL:如何选择本周的记录?

      时间:2023-06-26
    1. <tfoot id='RbMks'></tfoot>

        <i id='RbMks'><tr id='RbMks'><dt id='RbMks'><q id='RbMks'><span id='RbMks'><b id='RbMks'><form id='RbMks'><ins id='RbMks'></ins><ul id='RbMks'></ul><sub id='RbMks'></sub></form><legend id='RbMks'></legend><bdo id='RbMks'><pre id='RbMks'><center id='RbMks'></center></pre></bdo></b><th id='RbMks'></th></span></q></dt></tr></i><div id='RbMks'><tfoot id='RbMks'></tfoot><dl id='RbMks'><fieldset id='RbMks'></fieldset></dl></div>

        • <bdo id='RbMks'></bdo><ul id='RbMks'></ul>

          <small id='RbMks'></small><noframes id='RbMks'>

                  <tbody id='RbMks'></tbody>
                <legend id='RbMks'><style id='RbMks'><dir id='RbMks'><q id='RbMks'></q></dir></style></legend>
                本文介绍了MySQL:如何选择本周的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在 sqlfiddle 上有带有结构的表 temp:

                I have table temp with structure on sqlfiddle:

                id(int 11 primary key)
                name(varchar 100)
                name2(varchar 100)
                date(datetime)
                

                我想获得本周的记录,例如如果现在 21.11.2013 我想要 18.11.2013 到 24.11.2013(每周)的所有行

                I would like get record on this week, example if now 21.11.2013 i would like all rows on 18.11.2013 to 24.11.2013(on week)

                现在我看到下一个算法:

                Now I see next algorithm:

                1. 获取工作日
                2. 计算几天前是星期一
                3. 计算星期一的日期
                4. 计算未来的星期日
                5. 按日期提出请求

                请告诉我,是否存在更短的算法(最好在查询 MySQL 中)?

                Tell me please, is exist a shorter algorithm (preferably in the query MySQL)?

                ADD 问题是: 为什么要这个查询 选择日期 17.11.2013(Sunday) - 23.11.2013(Saturday) 以及如何获取日期 18.11.2013(Monday) - 24.11.2013(Sunday) 的记录) ?

                ADD Question is: Why this query select record on date 17.11.2013(Sunday) - 23.11.2013(Saturday) and how get records on date 18.11.2013(Monday) - 24.11.2013(Sunday) ?

                查询:

                select * from temp
                where yearweek(`date`) = yearweek(curdate())
                

                谢谢!

                推荐答案

                使用 YEARWEEK():

                SELECT *
                FROM   your_table
                WHERE  YEARWEEK(`date`, 1) = YEARWEEK(CURDATE(), 1)
                

                这篇关于MySQL:如何选择本周的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:接口错误 (0, '') 下一篇:如何用许多随机数填充 MySQL 表?

                相关文章

              • <tfoot id='0EoIp'></tfoot>
                  <bdo id='0EoIp'></bdo><ul id='0EoIp'></ul>

              • <i id='0EoIp'><tr id='0EoIp'><dt id='0EoIp'><q id='0EoIp'><span id='0EoIp'><b id='0EoIp'><form id='0EoIp'><ins id='0EoIp'></ins><ul id='0EoIp'></ul><sub id='0EoIp'></sub></form><legend id='0EoIp'></legend><bdo id='0EoIp'><pre id='0EoIp'><center id='0EoIp'></center></pre></bdo></b><th id='0EoIp'></th></span></q></dt></tr></i><div id='0EoIp'><tfoot id='0EoIp'></tfoot><dl id='0EoIp'><fieldset id='0EoIp'></fieldset></dl></div>

                1. <small id='0EoIp'></small><noframes id='0EoIp'>

                    <legend id='0EoIp'><style id='0EoIp'><dir id='0EoIp'><q id='0EoIp'></q></dir></style></legend>