gpt4 book ai didi

mysql - 使用 AND & OR 语句对 MySQL 来说是不是太糟糕了?

转载 作者:太空宇宙 更新时间:2023-11-03 10:57:40 25 4
gpt4 key购买 nike

我有一个这样的帖子表:

----- 帖子 -----
- 编号
- ..等..
- 类别 1
- 类别 2
- 类别 3

这些类别中的任何一个都可以被过滤,我正计划构建 SQL 语句,例如:

SELECT * 
FROM posts
WHERE category1='..sth..'
AND category1='..sth..'
OR category1='..sth..'
OR category2='..sth..'
OR category3='..sth..'
AND category3='..sth..'
OR ..."

这是一种不好的做法吗?这会带来性能问题吗?

编辑:我给出的查询中的 AND 和 OR 语句仅作为示例。

最佳答案

试试这个

    SELECT * FROM posts 
WHERE category1 in ('sth','sth')
OR category2 in ('sth','sth')
OR category3 in ('sth','sth')
.....

关于mysql - 使用 AND & OR 语句对 MySQL 来说是不是太糟糕了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18836607/

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