CREATE TABLE IF NOT EXISTS `photos` (
`p_id` bigint(20) unsigned NOT NULL auto_increment,
`u_id` bigint(20) unsigned NOT NULL default '0',
`p_date` datetime NOT NULL default '0000-00-00 00:00:00',
`p_content` longtext NOT NULL,
`p_title` text NOT NULL,
`p_photo` text NOT NULL,
`p_small` text NOT NULL,
`p_thumb` text NOT NULL,
`p_up` bigint(20),
`p_down` bigint(20),
PRIMARY KEY (`p_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=229 ;
我想要前10张最受好评的照片! 但因为有p_up(拇指向上)和p_down(拇指向下) 它的复杂! 有人可以帮忙吗?
答案 0 :(得分:2)
SELECT * FROM Table ORDER BY p_up - p_down DESC LIMIT 10
如果你在表格上创建INDEX foo(p_up - p_down)
会更快答案 1 :(得分:0)
以下查询将首先获取具有最大p_up - p_down值的照片:
select * from photos order by (p_up - p_down) desc;
答案 2 :(得分:0)
SELECT * FROM photos ORDER BY (p_up-p_down) DESC LIMIT 10