简体   繁体   English

PHP mysql多个选择查询不起作用

[英]PHP mysql multiple Select Query is not working

My sql Query is not working. 我的sql查询无法正常工作。 I need to filter a data with Location but it not works. 我需要使用“ Location filter data ,但是它不起作用。 Why this is not working 为什么这不起作用

$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'";

You need to update your query 您需要更新查询

IN ('chennai,Bangalore')

into

IN ('chennai','Bangalore')

try this table and query and analyst it hope will help you table as follows 尝试此表并查询和分析,希望对您有所帮助,如下所示

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');

This is the query to get your desired result 这是查询以获得您想要的结果

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM