我正在创建一个链接页面,它将显示按 live_date 排序的所有链接 - 这里的问题是有两种类型的链接 - 提升和非提升 - 另一个问题是 - 列表应该按天分组,所以今天的链接将返回提升的链接然后是非提升的链接 - 然后是昨天的提升和非提升。
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 ;
我是这样想的,但我认为它不会先创建所有提升的链接,然后再创建非提升的链接(由布尔定义)
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