mysql - 如何在 mysql 中使用带有 if else 条件的 Where 子句

标签 mysql

我有一个项目表,其中存储了所有项目和项目建议的列表。如果建议被接受,那么它们也会成为项目。

id  p_name  suggestion accepted
1   abc      0         pending
2   fgh      1         pending
3   aec      1         yes
4   etc      1         pending

现在我想要一个只显示以下行的查询。

id  p_name  suggestion accepted
1   abc      0         pending
2   aec      1         yes

是这样的

select * from table if('suggestion'== 1)then get only where('accepted','yes') otherwise get only those rows which have suggestion == 0

最佳答案

这个?

select
    *
from
    "table" t
where
    t.suggestion = 0
    or
    ( t.suggestion = 1 and t.accepted = 'yes' )

关于mysql - 如何在 mysql 中使用带有 if else 条件的 Where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46110218/

相关文章:

带有文本输入和图像 uploader 的 php 表单

php - MySQL 按一列对行进行分组并按另一列排序

Mysql:对连接两个表的查询感到困惑

php - CakePHP LDAP/MySQL 混合模型

Java远程连接

MySQL 复合聚合和不正确的语法?

php - 你好!我正在尝试使用联系表 7 在我的 mysql 数据库中插入行

php - 表和连接的 SQL 语法有误

php - 在Codeigniter中的同一个mysql表中上传图像和文本

php - 使用 php echo mysql 查询的几行和几列