2015-10-31 28 views
0

我的SQL查詢不工作。 我需要filter a dataLocation但它不起作用。爲什麼這是不工作PHP的MySQL多選擇查詢不工作

$sql = "SELECT count(*) FROM entries WHERE location 
IN ('chennai,Bangalore') AND en_id = 'test' AND date(datetime) 
BETWEEN '2015-10-02' AND '2015-10-31'"; 
+0

或者你可以嘗試**凡位置LIKE「%奈%」或位置LIKE「%班加羅爾%」 **是好的選擇,如果你匹配字符串 –

+0

你忘了撇號IN('chennai','Bangalore')AND –

回答

4

你需要更新你的查詢

IN ('chennai,Bangalore') 

IN ('chennai','Bangalore') 
+0

請停止downvoting回答,無需發佈原因。至少發佈downvoting的原因 –

1

試試這個表,查詢和分析人員希望能幫助你 表如下

CREATE TABLE IF NOT EXISTS `entries` (
`id` int(15) NOT NULL, 
`location` varchar(255) NOT NULL, 
`en_id` varchar(25) NOT NULL , 
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP 
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; 

-- 
-- Dumping data for table `entries` 
-- 

INSERT INTO `entries` (`id`, `location`, `en_id`, `date`) VALUES 
(1, 'chennai', 'test', '2015-10-31 12:53:38'), 
(2, 'Bangalore', 'test', '2015-10-31 12:53:38'), 
(3, 'chennai', 'test', '2015-10-13 12:53:38'), 
(4, 'chennai', 'test', '2015-10-05 12:53:38'), 
(5, 'chennai', 'test1', '2015-10-03 00:00:00'), 
(6, 'Bangalore', 'test', '2015-10-04 12:53:38'), 
(7, 'Bangalore', 'test1', '2015-10-03 00:00:00'), 
(8, 'chennai', 'test1', '2015-10-30 00:00:00'), 
(9, 'Bangalore', 'test1', '2015-10-30 00:00:00'); 

這是查詢得到你想要的結果

SELECT count(*) FROM entries WHERE location 
IN ('chennai','Bangalore') AND en_id = 'test1' AND date(NOW()) 
BETWEEN '2015-10-02' AND '2015-10-31'