我有數據,這種格式爲什麼這個查詢返回空行?
CREATE TABLE IF NOT EXISTS `historical_data` (
`symbol_name` varchar(70) DEFAULT NULL,
`current_day` varchar(50) DEFAULT NULL,
`open_val` varchar(20) DEFAULT NULL,
`high_val` varchar(20) DEFAULT NULL,
`low_val` varchar(20) DEFAULT NULL,
`close_val` varchar(20) DEFAULT NULL,
`last_val` varchar(20) DEFAULT NULL,
`prevclose_val` varchar(20) DEFAULT NULL,
UNIQUE KEY `symbol_name` (`symbol_name`,`current_day`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `historical_data` (`symbol_name`, `current_day`, `open_val`, `high_val`, `low_val`, `close_val`, `last_val`, `prevclose_val`) VALUES
('IBWSL', '10-DEC-2015', '9.35', '9.8', '9', '9.45', '9.6', '9.5'),
('ICICIBANK', '10-DEC-2015', '260.85', '261.9', '256', '258.95', '258.65', '259.45'),
('ICIL', '10-DEC-2015', '981', '1004.2', '981', '989.7', '992', '988.45'),
('ICNX100', '10-DEC-2015', '86.8', '87.99', '86.8', '87', '87', '82.5'),
('ICRA', '10-DEC-2015', '4175', '4280', '4144', '4211.4', '4279.95', '4175.3'),
('ZYDUSWELL', '14-DEC-2015', '815.75', '815.75', '785.25', '810.7', '810.5', '803.1'),
('ZYLOG', '14-DEC-2015', '2.9', '2.95', '2.85', '2.95', '2.95', '2.19');
/*!40000 ALTER TABLE `historical_data` ENABLE KEYS */;
我寫的查詢這樣
select * from (
select
symbol_name ,
(prevclose_val-close_val) as losers,
'daily' as `type`
from
historical_data
where
current_day >= STR_TO_DATE('14-DEC-2015', '%d-%MMM-%Y')
order by losers asc limit 10
) as sub_daily
這是我sqlfiddle
http://sqlfiddle.com/#!9/b4819
你不需要'current_day'上的'STR_TO_DATE()'嗎? –