基于不同的周开始和结束日期获取数据

vs3odd8k  于 2021-06-24  发布在  Mysql
关注(0)|答案(2)|浏览(350)

这个问题在这里已经有答案了

如何使用mysql在两个日期之间进行查询(10个答案)
两年前关门了。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Data</title>
</head>
<body>
<table border=1>
<tr>
<td bgcolor=silver class='medium'>name</td>
<td bgcolor=silver class='medium'>last_name</td>
<td bgcolor=silver class='medium'>email</td>
<td bgcolor=silver class='medium'>start_date</td>
<td bgcolor=silver class='medium'>end_date</td>
</tr>

<tr>
<td class='normal' valign='top'>venky</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-06-25</td>
<td class='normal' valign='top'>2018-07-01</td>
</tr>

<tr>
<td class='normal' valign='top'>raki</td>
<td class='normal' valign='top'>asd</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-06-25</td>
<td class='normal' valign='top'>2018-07-01</td>
</tr>

<tr>
<td class='normal' valign='top'>rakesh</td>
<td class='normal' valign='top'>raki</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-06-25</td>
<td class='normal' valign='top'>2018-07-01</td>
</tr>

<tr>
<td class='normal' valign='top'>venkatesh</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-06-25</td>
<td class='normal' valign='top'>2018-07-01</td>
</tr>

<tr>
<td class='normal' valign='top'>jhon</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-06-25</td>
<td class='normal' valign='top'>2018-07-01</td>
</tr>

<tr>
<td class='normal' valign='top'>venky</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-02</td>
<td class='normal' valign='top'>2018-07-08</td>
</tr>

<tr>
<td class='normal' valign='top'>raki</td>
<td class='normal' valign='top'>asd</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-02</td>
<td class='normal' valign='top'>2018-07-08</td>
</tr>

<tr>
<td class='normal' valign='top'>rakesh</td>
<td class='normal' valign='top'>raki</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-02</td>
<td class='normal' valign='top'>2018-07-08</td>
</tr>

<tr>
<td class='normal' valign='top'>venkatesh</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-02</td>
<td class='normal' valign='top'>2018-07-08</td>
</tr>

<tr>
<td class='normal' valign='top'>jhon</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-02</td>
<td class='normal' valign='top'>2018-07-08</td>
</tr>

<tr>
<td class='normal' valign='top'>venky</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-09</td>
<td class='normal' valign='top'>2018-07-15</td>
</tr>

<tr>
<td class='normal' valign='top'>raki</td>
<td class='normal' valign='top'>asd</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-09</td>
<td class='normal' valign='top'>2018-07-15</td>
</tr>

<tr>
<td class='normal' valign='top'>rakesh</td>
<td class='normal' valign='top'>raki</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-09</td>
<td class='normal' valign='top'>2018-07-15</td>
</tr>

<tr>
<td class='normal' valign='top'>venkatesh</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-09</td>
<td class='normal' valign='top'>2018-07-15</td>
</tr>

<tr>
<td class='normal' valign='top'>jhon</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-09</td>
<td class='normal' valign='top'>2018-07-15</td>
</tr>

<tr>
<td class='normal' valign='top'>venky</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-16</td>
<td class='normal' valign='top'>2018-07-22</td>
</tr>

<tr>
<td class='normal' valign='top'>raki</td>
<td class='normal' valign='top'>asd</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-16</td>
<td class='normal' valign='top'>2018-07-22</td>
</tr>

<tr>
<td class='normal' valign='top'>rakesh</td>
<td class='normal' valign='top'>raki</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-16</td>
<td class='normal' valign='top'>2018-07-22</td>
</tr>

<tr>
<td class='normal' valign='top'>venkatesh</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-16</td>
<td class='normal' valign='top'>2018-07-22</td>
</tr>

<tr>
<td class='normal' valign='top'>jhon</td>
<td class='normal' valign='top'>sai</td>
<td class='normal' valign='top'>ascd@gmail.com</td>
<td class='normal' valign='top'>2018-07-16</td>
<td class='normal' valign='top'>2018-07-22</td>
</tr>
</table>
</body></html>

我有这样的数据。如果我选择开始日期:'2018-06-25'和结束日期:'2018-07-01'。我应该得到那周的数据。如果选择一周中的任何开始日期和结束日期。我应该得到那周的数据。示例开始日期:'2018-06-28'和结束日期:'2018-07-09'。如果我选择开始日期:'2018-06-25'和结束日期:'2018-07-11'。我应该得到三周的数据。这可能吗?

hi3rlvi2

hi3rlvi21#

SELECT * FROM yourTable WHERE start_date::date > '2018-06-25' and end_date::date < '2018-07-01'
1l5u6lss

1l5u6lss2#

而不是 Start_date:'2018-06-28' and end_date:'2018-06-09' 你应该使用 >= 以及 <=where 子句,它可能看起来像这样:

select * from your_table where Start_date >= '2018-06-09' and end_date <= '2018-06-28'

相关问题