我的sql查询无效。
我需要filter
data
Location
,但不起作用。为什么这不起作用
$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 :(得分:4)
您需要更新查询
IN ('chennai,Bangalore')
进入
IN ('chennai','Bangalore')
答案 1 :(得分: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'