mysql - SQL:如何在 Sql 中使用条件 AND 和 OR

标签 mysql sql relational-database

我的表格具有以下值

docid dcname doctitle 
1      **aa   **aaa01-01 
2      aa**   aafddg-02**
3      a**a   asds***90-05
4      abcd   abcd-06.

现在在这个表中我想过滤以 ** 开头和结尾的“Doctitles”值

我的结果应该是

dcid docname doctitle
3    a**a    asds***90-05
4    abcd    abcd-06

我正在使用下面的查询,但获得的结果只是中间带有**的Doctitles

SELECT *
  FROM table1
 WHERE     doctitle NOT LIKE '**%'
       AND doctitle NOT LIKE '%**'
       AND doctitle LIKE '%**%'

这仅给我以下结果 dcid 文档名称 文档标题 3 a*a asds**90-05

需要这方面的帮助。

最佳答案

尝试以下选项

select * from table1 where doctitle like '**%' and doctitle like '%**'

select * from table1 where doctitle like '**%'
UNION
select * from table1 where doctitle like '%**'

更多详情请参阅this

关于mysql - SQL:如何在 Sql 中使用条件 AND 和 OR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19628053/

相关文章:

php - 内部连接 ​​Eloquent as JSON,错误的答案

sql - 在 sql join 中合并部分重复的行

mysql - SQL:从多个表中查询相关数据

architecture - 现有关系数据库上的 Cqrs 和事件溯源

mysql - Git Bash mysql 空白

编写查询需要 MySQL 帮助

sql - 如何在 PostgreSQL 中有效地设置减法连接表?

mysql - 如何在关系数据库中存储不同版本的数据?

mysql - 更新mysql中的日期格式

php mysql 表单将结果从数据库传递到原始表单字段