MySQL社区

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 4797|回复: 1
打印 上一主题 下一主题

如何高效返回每个infomation中info_comment得票数最多的commentContent

[复制链接]
跳转到指定楼层
1#
发表于 2010-2-21 21:21:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
infomation信息表 字段 infoID
info_comment信息评论表   字段 commentID,infoID,commentContent
comment_vote 用户投票表    字段 commentID,infoID,voterID
如何高效返回每个infomation中info_comment得票数最多的commentContent?怎么用上索引?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 分享淘帖 顶 踩
2#
 楼主| 发表于 2010-2-21 21:26:42 | 只看该作者
我自己写的方法,感觉很不好:
select * from info_comment d,
(SELECT *
FROM (

SELECT *
FROM (

SELECT infoID, commentID, count( commentID ) AS commentCount
FROM `comment_vote`
GROUP BY infoID, commentID
) AS a
ORDER BY infoID, commentCount DESC
) AS b
GROUP BY infoID) as c
where d.infoID=c.infoID and d.commentID=c.commentID
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|申请友链|小黑屋|Archiver|手机版|MySQL社区 ( 京ICP备07012489号   
联系人:周生; 联系电话:13911732319

GMT+8, 2024-6-16 06:55 , Processed in 0.068178 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表