我的查询有问题。 这是我的视频表结构列表
+----+----------+---------------+
| id | category | subcategory |
+----+----------+---------------+
| 91 | 1 | 1,3,6,8,10,14 |
| 90 | 1 | 1,7,8,9,10 |
| 89 | 1 | 1,6,8 |
| 88 | 1 | 1,7,8,9,10 |
| 87 | 1 | |
| 86 | 1 | 1,6,8,10,11 |
| 84 | 2 | 2,11,13 |
| 83 | 1 | 1,8,10,11 |
| 82 | 3 | 3 |
| 81 | 1 | 1,6,7,9,10 |
+----+----------+---------------+
现在我只想选择特定类别中的视频,如果视频属于同一类别,也应该显示。
我的查询是这样的:
SELECT id
FROM video_details
WHERE display_active='1'
OR category IN (3)
AND (FIND_IN_SET("3",subcategory))
ORDER BY actress
DESC LIMIT 0, 15
它的输出是这样的:
+----+
| id |
+----+
| 89 |
| 88 |
| 86 |
| 84 |
| 82 |
| 81 |
| 80 |
| 79 |
| 78 |
| 77 |
| 76 |
| 75 |
| 74 |
| 73 |
| 72 |
+----+
正如您所看到的,视频ID 89在子类别列中的类别不是3,也包含其他类别。
你能帮我解决这个问题吗?
答案 0 :(得分:0)
使用时
display_active='1'
OR category IN (3)
AND (FIND_IN_SET("3",subcategory))
表示display_active =' 1' AND(FIND_IN_SET(" 3",子类别))将输出或类别IN(3)将输出。所以ID 89显示。如果我找到你,我猜你需要这个:
SELECT id
FROM video_details
WHERE display_active='1'
OR ( category IN (3)
AND (FIND_IN_SET("3",subcategory)) )
ORDER BY actress
DESC LIMIT 0, 15