2015-03-02 95 views
0

我在尝试查找所有最后修改日期大于2015-03-01并且名称列为空的条目。 这是我写的mySQL错误1064:澄清

SELECT * FROM `inventory` where date(date_modified) >= date '2015-03-01' AND where name is not null ORDER BY `inventory`.`date_modified` DESC 

我得到错误1064当我尝试运行此查询的查询。

+0

'日期(DATE_MODIFIED)> =日期 '2015-03-01''可以简化为'DATE_MODIFIED> =' 2015-03-01'' – 2015-03-03 01:50:29

回答

0

您需要围绕参数date的圆括号。此外,在AND之后,您不会重复WHERE关键字。

SELECT * FROM `inventory` 
where date(date_modified) >= date('2015-03-01') 
AND name is not null 
ORDER BY `inventory`.`date_modified` DESC 
0

你的描述,你说

名称的列是空

您的查询你说:

其中名称不为空

哪一个是正确的?

由于您的查询有两次使用WHERE,因此您的查询语法错误,您正在获得。

SELECT ...WHERE .... AND WHERE 

这是这样做的。请更改为空或不为空取决于你想要什么

SELECT 
    * 
FROM 
    inventory 
WHERE 
    date(date_modified) >= date('2015-03-01') AND name is null -- is not null 
ORDER BY inventory.date_modified DESC 
+0

我的意思是名字栏已满。我很抱歉的混淆。我正在尝试学习mySQL。 – Ria 2015-03-03 22:49:19

+0

不用担心。我们都在学习。你试过我的选择吗?如果您遇到问题/错误,请告诉我。 – 2015-03-03 23:41:46