我有一个mysql函数
SELECT * FROM `stats` WHERE BETWEEN '2011-01-03' AND '2011-01-01' AND `email`='sarah@sarah.com' AND `city`='New York' AND `location`='New York' AND `date` GROUP BY action
然而,我似乎无法让它工作,如果我拿出BETWEEN'2011-01-03'和'2011-01-01',但没有使用它,它是如何工作的,我怎么能使这个功能工作?
答案 0 :(得分:11)
WHERE BETWEEN '2011-01-03' AND '2011-01-01'
需要比较列名。是date
列吗?
然后您的查询应如下所示:
SELECT *
FROM `stats`
WHERE `date` BETWEEN '2011-01-01' AND '2011-01-03'
AND `email`='sarah@sarah.com'
AND `city`='New York'
AND `location`='New York'
GROUP BY action
答案 1 :(得分:3)
添加日期字段的名称和
然后
更改订单
date BETWEEN '2011-01-01' AND '2011-01-03'
首先是最早的日子,然后是最晚的日期
答案 2 :(得分:3)
使用
(min< = expr AND expr< = max)
代替或使用大括号。
答案 3 :(得分:3)
在使用条件
之前使用列名喜欢As:
Date BETWEEN '2011-01-01' AND '2011-01-03'
在您忘记在 BETWEEN 关键字
之前放置“日期”字段的SQL<强>语法强>
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
答案 4 :(得分:2)
SELECT * FROM `stats` WHERE COLUMN-NAME-HERE BETWEEN
注意COLUMN-NAME-这里需要日期字段
答案 5 :(得分:2)
你应该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`='sarah@sarah.com' AND `city`='New York' AND `location`='New York' AND `date` GROUP BY action
答案 6 :(得分:0)
将时间添加到日期:
$qAddDate = " AND (dCreated >= '".$_POST['datefrom']."' AND dCreated <= '".$_POST['dateto'].":23:59:59')";