English 中文(简体)
利用BETWEEN条件按日期返回,但没有结果
原标题:Trying to use BETWEEN condition to return rows based on date but getting no results

我有一个包含活动清单的数据库,其格式类似:

  Datef        Event        Location       Discipline
10/01/2012  MG Training    Brooklands          MG

我正在问这个问题,以便在某些日期之间取得结果:

SELECT * FROM events WHERE Discipline IN ( MG ) AND Datef BETWEEN 01/01/2012 AND 31/01/2012

查询过程是正确的,我知道数据库有相关结果,但我没有在管理Sphpmyadmin的查询结果(我刚刚被告知“Yourkou query已经成功执行”。)

我很想知道,是否有任何想法说明为什么这种结果不会恢复?

Update: Putting dates in quotes (e.g. SELECT * FROM events WHERE Discipline IN ( MG ) AND Datef BETWEEN 01/01/2012 AND 31/01/2012) kinda works but there s a bug. I ve certain dates doesn t work. e.g.

SELECT * FROM events WHERE Discipline IN ( COMM ) AND Datef BETWEEN  2012-02-01  AND  2012-02-29 
shows no results, even though there is an event on 2010-02-01. Is this a peculiarity in the BETWEEN algorithm, or am I still getting my query wrong?
问题回答

如果不引述这些价值观或把这些价值定为日期的话,那么你所写的那份文字就只能是数学。

换言之,你要求

 BETWEEN 01/01/2012 AND 31/01/2012

因此,你获得1/1=1,然后是1/2012,几乎是0。

然后是31/1=31,然后是31/2012,近0。

因此它就变成了它。

BETWEEN 0 and 0

摘录你的代码。 MySQL和PHP使用不同的格式。

对于另外的一些胎儿,这里还有两条联系:

http://www.richardlord.net/blog/dates-in-php-and-mysql http://www.binarytides.com/blog/parse-and-format-dates-between-php-and-mysql/

页 次 日期f为错误类型,应为数据时间

SELECT
    *
FROM
    `events`
WHERE
    `Discipline` IN ( MG )
AND
    `Datef` BETWEEN  2012-01-01  AND  2012-01-31 




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签