between

MySQL “between” clause not inclusive?

妖精的绣舞 提交于 2019-11-26 04:43:01
问题 If I run a query with a between clause, it seems to exclude the ending value. For example: select * from person where dob between \'2011-01-01\' and \'2011-01-31\' This gets all results with dob from \'2011-01-01\' till \'2011-01-30\'; skipping records where dob is \'2011-01-31\'. Can anyone explain why this query behaves this way, and how I could modify it to include records where dob is \'2011-01-31\'? (without adding 1 to the ending date because its been selected by the users.) 回答1: The

Mysql: Select all data between two dates

不羁的心 提交于 2019-11-26 00:33:53
问题 I have a mysql table with data connected to dates. Each row has data and a date, like this: 2009-06-25 75 2009-07-01 100 2009-07-02 120 I have a mysql query that select all data between two dates. This is the query: SELECT data FROM tbl WHERE date BETWEEN date1 AND date2 My problem is that I also need to get the rows between date1 and date2 even if there is no data for a day. So my query would miss the dates that are empty between 2009-06-25 and 2009-07-01. Can I in some way add these dates

generate days from date range

眉间皱痕 提交于 2019-11-25 21:42:59
问题 I would like to run a query like select ... as days where `date` is between \'2010-01-20\' and \'2010-01-24\' And return data like: days ---------- 2010-01-20 2010-01-21 2010-01-22 2010-01-23 2010-01-24 回答1: This solution uses no loops, procedures, or temp tables . The subquery generates dates for the last 10,000 days, and could be extended to go as far back or forward as you wish. select a.Date from ( select curdate() - INTERVAL (a.a + (10 * b.a) + (100 * c.a) + (1000 * d.a) ) DAY as Date