dongmangji0950 2010-09-21 14:28
浏览 128
已采纳

Mysql选择带有两个stringlist的find_in_set

I got in my table this 2 rows:

1, 'Halo: Reach', 2010, ''fps','sci-fi'', '"The best game of the year".', 'Microsoft', 'Bungie', 'XBOX 360', 9.5, 'http://wuwb.com/wp/wp-content/uploads/2009/06/halo_reach.thumbnail.jpg', '', ''

2, 'FIFA 11', 2010, 'sport,soccer', '"The best soccer game ever"', 'EA', 'EA', 'PC, XBOX 360, PS3', 10, 'http://wuwb.com/wp/wp-content/uploads/2009/06/halo_reach.thumbnail.jpg', '', ''

And in my php script I got:

$Genres = "sci-fi,sport,soccer"; // After using the sumbit button

I need to make a select query that order by genres, so FIFA 11 would be first and halo:reach second. So I tried to use find_in_set but it not working with two string list.

The only option I think about was to do for each genre IN clause and order by some fields and making limit, but I think its really bad way to do this.

  • 写回答

2条回答 默认 最新

  • dongxing9219 2010-09-21 21:03
    关注

    I found better way :D

    I created a new table (gamesgenres), so for every game I got some rows there.

    SELECT count(games.id) as relevance, GROUP_CONCAT(gamesgenres.genre) as genres, games.* FROM games, gamesgenres WHERE ('sci-fi' IN (gamesgenres.genre) OR 'soccer' IN (gamesgenres.genre) OR 'fps' IN (gamesgenres.genre)) AND gamesgenres.game = games.genres group by games.id ORDER BY relevance DESC;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决