我正在创建一个链接页面,它将显示按live_date排序的所有链接 - 这里的catch是有两种类型的链接 - 提升和非提升 - 其他捕获是 - 列表应按天分组,所以今天链接将返回提升的链接,然后是非提升的链接 - 然后昨天提升和未提升。
Fridays links
-------------
Promoted link
Promoted link
Promoted link
Normal link
Normal link
Thursdays Links
--------------
Promoted link
Normal link
Normal link
Normal link
等等 -
我的架构:
CREATE TABLE `links` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) NOT NULL,
`email` varchar(200) NOT NULL,
`link` varchar(200) NOT NULL,
`reciprocal_checkbox` tinyint(1) NOT NULL,
`recip` varchar(200) NOT NULL,
`promoted` tinyint(1) NOT NULL,
`live` tinyint(1) NOT NULL,
`live_time` datetime NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
我认为这样的事情,但我认为它不会创建所有提升的链接,然后是非提升的(由bool定义)
SELECT title, link, live_time FROM links WHERE promoted = 1 UNION SELECT title, link, live_time FROM links WHERE promoted = 0 GROUP BY live_date
答案 0 :(得分:2)
你不想分组,你只想订购它们......
SELECT title, link, live_time
FROM links
ORDER BY live_date DESC, promoted DESC
PS - 看起来您没有live_date
列。你想要这样的东西吗?
SELECT title, link, live_time
FROM links
ORDER BY DATE(live_time) DESC, promoted DESC
答案 1 :(得分:0)
这个怎么样?
SELECT title, link, live_time FROM links
ORDER BY live_date, promoted