gpt4 book ai didi

php - MySQL选择流派问题(php)

转载 作者:行者123 更新时间:2023-11-29 01:24:35 24 4
gpt4 key购买 nike

我有一个数据库:

id       |                movie_name              |           genres
1 | Die Hard | Action, Thriller
2 | Gladiator | Adventure, Action, Drama, History
3 | Harry Potter and the Sorcerers Stone | Fantasy, Adventure, Family
4 | Pearl Harbor | Action, Melodrama, War

1)如何从所有数据库的流派中选择独特的流派。我需要下一个: Action /冒险/剧情/家庭/奇幻/历史/情节剧/惊悚/ war

2)如何观看特定类型的电影?

SELECT `movie_name` FROM `movies` WHERE `genre` LIKE ??

但他不仅能带来戏剧,还能带来情节剧。

3) 如何搜索特定类型?可能是:

 SELECT `movie_name` FROm `movies` WHERE `movie_name` LIKE `%stone%` AND `genres LIKE 'drama'.

最佳答案

不要在数据库列中存储以逗号分隔的属性列表。

相反,有 3 个表:

Movies (id, movie_name)

id | movie_name
---+--------------------------------------
1 | Die Hard
2 | Gladiator
3 | Harry Potter and the Sorcerers Stone
4 | Pearl Harbor

Genres (id, genre_name)

id | genre_name
---+------------
1 | Action
2 | Thriller
3 | Adventure
4 | Drama
5 | History
6 | Fantasy
7 | Family
8 | Melodrama
9 | War

MovieGenre (movie, genre)

Movie | Genre
------+-------
1 | 1
1 | 2
2 | 1
2 | 3
2 | 4
2 | 5
3 | 3
3 | 6
3 | 7
4 | 1
4 | 8
4 | 9

那么你的问题就会变得非常非常简单。

关于php - MySQL选择流派问题(php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5423893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com