根据不同的星期开始和结束日期获取数据

时间:2018-06-27 11:54:08

标签: mysql sql date

<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”。我应该得到三个星期的数据。这可能吗?

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

您应该在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'