表格的基本结构
event_id | event_name | start_time | end_time |日期
我正在尝试以他们结束的顺序获取事件
查询我试过: -
SELECT * FROM `tablename` ORDER BY date,end_time DESC
但我没有得到预期的结果。
PS: end_time的类型为time
,日期的类型为date
编辑:表转储以进行测试
CREATE TABLE IF NOT EXISTS `wp_deals` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`title` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
`p_id` bigint(20) NOT NULL,
`end_time` time NOT NULL,
`start_time` time NOT NULL,
`lastactive` date NOT NULL,
`alldates` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
`status` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`live` tinyint(2) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=17 ;
--
-- Dumping data for table `wp_deals`
--
INSERT INTO `wp_deals` (`id`, `title`, `p_id`, `end_time`, `start_time`, `lastactive`, `alldates`, `status`, `live`) VALUES
(12, 'checking', 70, '13:00:00', '12:30:00', '2014-08-11', '2014-08-09,2014-08-11', 'completed', 1),
(13, 'dealajax', 11, '12:00:00', '11:30:00', '2014-08-11', '2014-08-09,2014-08-11', 'completed', 1),
(16, 'testprodone', 11, '11:40:00', '10:48:00', '2014-08-10', '2014-08-10', 'completed', 1),
(11, 'report test', 70, '11:45:00', '11:35:00', '2014-08-09', '2014-08-09', 'completed', 1),
(9, 'next deal', 70, '15:50:00', '09:20:00', '2014-08-08', '2014-08-07,2014-08-08', 'completed', 1),
(10, 'Deal 2', 11, '12:30:00', '12:00:00', '2014-08-11', '2014-08-08,2014-08-11', 'completed', 1);
答案 0 :(得分:2)
我的猜测是你想要最近的日期。如果是这样,您需要desc
两次:
SELECT *
FROM `tablename`
ORDER BY `date` DESC, `end_time` DESC;
您的版本从最早的日期开始。这似乎没那么有用。