<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:如何选择本周的记录?

      MySQL: How to select records for this week?(MySQL:如何选择本周的记录?)
    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:如何选择本周的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to delete duplicate records in mysql database?(如何删除mysql数据库中的重复记录?)
                Python Pandas write to sql with NaN values(Python Pandas 使用 NaN 值写入 sql)
                MySQL Insert amp; Joins(MySQL 插入 amp;加入)
                MySQL concat() to create column names to be used in a query?(MySQL concat() 创建要在查询中使用的列名?)
                NodeJS responded MySQL timezone is different when I fetch directly from MySQL(当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同)
                WHERE datetime older than some time (eg. 15 minutes)(WHERE 日期时间早于某个时间(例如 15 分钟))

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

                    • <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>