我正在调整脚本的性能,并更改了帖子类别的排序方式。
我成功使用了以下查询。它选择具有 (130|3|4|5) 类别的帖子,并检查它是否也具有 (73) 类别 init,因为一个帖子可以有多个类别。
SELECT *
FROM post
LEFT JOIN post_plus
ON ( post.id = post_plus.news_id )
WHERE category REGEXP '[[:<:]](130|3|4|5)[[:>:]]'
AND category REGEXP '[[:<:]](73)[[:>:]]'
AND approve = 1
ORDER BY fixed DESC,
date DESC
LIMIT 0, 7
现在有了一个新查询,我需要执行多个 IN (...) 查询而不是AND category REGEXP '...'
,但由于某种原因,附加AND categoryid IN
总是返回空结果。
SELECT *
FROM post
LEFT JOIN post_plus
ON ( post.id = post_plus.news_id )
LEFT JOIN post_category
ON ( post_category.postid = post.id )
WHERE categoryid IN ( 130, 3, 4, 5 )
AND categoryid IN ( 73 )
AND approve = 1
ORDER BY fixed DESC,
date DESC
LIMIT 0, 7;
post_category 结构
+-----+--------+------------+
| cid | postId | categoryId |
+-----+--------+------------+
| 824 | 7 | 10 |
| 825 | 7 | 13 |
| 826 | 7 | 16 |
| 827 | 7 | 29 |
| 828 | 7 | 71 |
+-----+--------+------------+