mysql 在哪里和等于?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4594183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql where between and equal to?
提问by Steven
I have a mysql function
我有一个 mysql 函数
SELECT * FROM `stats` WHERE BETWEEN '2011-01-03' AND '2011-01-01' AND `email`='[email protected]' AND `city`='New York' AND `location`='New York' AND `date` GROUP BY action
However I can't seem to get it working, it works if I take out the BETWEEN '2011-01-03' AND '2011-01-01' but not with it in, how can I make this function work?
但是我似乎无法让它工作,如果我取出 BETWEEN '2011-01-03' AND '2011-01-01' 但没有它,我怎样才能使这个功能工作?
回答by eumiro
WHERE BETWEEN '2011-01-03' AND '2011-01-01'
needs a column name to be compared. Is it the date
column?
需要一个列名进行比较。是date
柱子吗?
Then your query should look like this:
那么您的查询应如下所示:
SELECT *
FROM `stats`
WHERE `date` BETWEEN '2011-01-01' AND '2011-01-03'
AND `email`='[email protected]'
AND `city`='New York'
AND `location`='New York'
GROUP BY action
回答by Haim Evgi
add the name of date field and
添加日期字段的名称和
then
然后
change the order
改变顺序
date BETWEEN '2011-01-01' AND '2011-01-03'
first the earliest day and after that the latest date
首先是最早的日期,然后是最晚的日期
回答by Tobias
Use
用
(min<= expr AND expr<= max)
(min<= expr AND expr<= max)
instead or use braces.
代替或使用大括号。
回答by Nikunj K.
Use column name before using between condition
在条件之间使用之前使用列名
Like As:
喜欢作为:
Date BETWEEN '2011-01-01' AND '2011-01-03'
In your SQL You Forgot to put "Date"Field before BETWEENKeyword
在您的 SQL 中,您忘记在BETWEEN关键字之前放置“日期”字段
Syntax
句法
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
回答by Norm
SELECT * FROM `stats` WHERE COLUMN-NAME-HERE BETWEEN
Notice COLUMN-NAME-HERE you need the date field
注意 COLUMN-NAME-HERE 您需要日期字段
回答by cristian
Hei you should have WHERE date_column BETWEEN '2011-01-03' AND '2011-01-01'
put the exact name of your column instead of date_column
so you'll have
嘿,您应该输入WHERE date_column BETWEEN '2011-01-03' AND '2011-01-01'
列的确切名称,而不是date_column
这样,您将拥有
SELECT * FROM `stats` WHERE `your_date_column` BETWEEN '2011-01-03' AND '2011-01-01' AND `email`='[email protected]' AND `city`='New York' AND `location`='New York' AND `date` GROUP BY action
回答by jeroen
Add the time to the date:
将时间添加到日期:
$qAddDate = " AND (dCreated >= '".$_POST['datefrom']."' AND dCreated <= '".$_POST['dateto'].":23:59:59')";