找到1周最大的输家

时间:2015-12-15 13:20:17

标签: mysql

我有以下数据

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 STR_TO_DATE(current_day, '%d-%M-%Y')  >= STR_TO_DATE('14-DEC-2015', '%d-%M-%Y') 
        ORDER BY losers ASC 
        LIMIT 10 
      ) AS sub_daily;

你能否告诉我同样可以根据当前日期返回最佳输家1周

这是我的小提琴

http://sqlfiddle.com/#!9/b4819/8

1 个答案:

答案 0 :(得分:2)

使用此查询,您可以找到过去7天的宽松。

val$numbers
true