对 MYSQL 中的数据库条目进行排名
我正在尝试根据用户保存该术语的次数对数据库中的条目进行排名。
因此,如果我的表是,
id laptop Price 1 Macbook $2000 2 MBP $2300 3 MBP $2300 4 MBP $2000
查询将返回
1.) MBP 2.) Macbook
我愚蠢地认为排名 GROUP_BY 和 DESC 可以做到这一点,然后我尝试了 @Rank := @Rank +1 方法但无济于事。 [我必须承认,我不确定这是否是解决问题的正确方法]
SET @rank :=0; SELECT * FROM ( SELECT d.*, @rank := @rank + 1 FROM data d ORDER BY d.`laptop` ) d2 WHERE d2.laptop = 'MBP'
感谢您的帮助。
I'm trying to rank the entries in my database, based on the number of times a user saves that term.
So if my table is ,
id laptop Price 1 Macbook $2000 2 MBP $2300 3 MBP $2300 4 MBP $2000
The query will return
1.) MBP 2.) Macbook
I foolishly thought ranking GROUP_BY and DESC would do this, then I tried the @Rank := @Rank +1 approach to no avail. [I must admit, i'm not sure if this is the right way to solve the problem]
SET @rank :=0; SELECT * FROM ( SELECT d.*, @rank := @rank + 1 FROM data d ORDER BY d.`laptop` ) d2 WHERE d2.laptop = 'MBP'
Thanks for any assistance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么这行不通?
Why won't that work?