日期:2014-05-16  浏览次数:20760 次

100高分求sql
数据库 mysql

表pic(pic_is,user_id,comment_num,praise_num,browser_num,hot_status)

hot_status 为图片状态(1,2,3),其中3表示是热图。


我想查出用户id(去重)列表,并且是按这个计算权重的倒序排序,
计算公式:comment_num*2+praise_num+browser_num*0.2+热图数*3

就是说按某个用户的所有图片的评论总数*2加上他的所有图片的赞数,加上他的所有图片的浏览数*0.2,再加上他的所有热图数*3,按这个计算出来的值倒序排序……

不知道我说的明白不。

在线,等高手回答,,,,,

跪求……

------解决方案--------------------
SQL code
select *
from (
select userid,sum(comment_num)*2+sum(praise_num)+sum(browser_num)*0.2+sum(热图数)*3 as quanzhong
from tb
group by user_id
) D
order by quanzhong desc
limit 10;

------解决方案--------------------
SQL code
select user_id, sum(comment_num*2+praise_num+browser_num*0.2+热图数*3)
form pic
group by user_id
order by 2 desc

------解决方案--------------------
探讨

SQL code
select *
from (
select userid,sum(comment_num)*2+sum(praise_num)+sum(browser_num)*0.2+sum(热图数)*3 as quanzhong
from tb
group by user_id
) D
order by quanzhong desc
limit 10;

------解决方案--------------------
贴建表及插入记录的SQL,及要求结果出来看看


select userid,sum(comment_num)*2+sum(praise_num)+sum(browser_num)*0.2+sum(热图数)*3 as quanzhong
from tb
group by user_id order by 2 desc
------解决方案--------------------
SQL code
SELECT  userid,SUM(comment_num)*2+SUM(praise_num)+SUM(browser_num)*0.2+SUM(热图数)*3 as quanzhong
FROM  tb
GROUP BY  user_id ORDER BY  2 DESC;

------解决方案--------------------
热图数要另外统计的吧。。
------解决方案--------------------
select userid,sum(comment_num)*2+sum(praise_num)+sum(browser_num)*0.2+
sum(if(hot_status=3,1,0))*3 as quanzhong
from tb
group by user_id order by 2 desc
------解决方案--------------------
探讨

select userid,sum(comment_num)*2+sum(praise_num)+sum(browser_num)*0.2+
sum(if(hot_status=3,1,0))*3 as quanzhong
from tb
group by user_id order by 2 desc