过滤条件查询

时间:2017-06-20 04:54:28

标签: mysql sql database

我有一张这样的表

Assigned_job|Assignedbyuser|Approve

8999        |co-admin1     |0

8888        |co-admin2     |1

7777        |co-admin3     |0

现在,如果我只想获得Approve = 1
我可以简单地使用

where Approve = 1

我会得到这个结果

Assigned_job|Assignedbyuser|Approve
8888        |co-admin2     |1

如果我想要

only Approve=1 but if Assignedbyuser='co-admin1' don't check Approve =1

最终结果看起来应该是这样的

Assigned_job|Assignedbyuser|Approve
8999        |co-admin1     |0
8888        |co-admin2     |1

4 个答案:

答案 0 :(得分:1)

ANDOR条件的组合:

WHERE
    (AssignedByUser <> 'co-admin1' AND Approve = 1)
    OR (AssignedByUser = 'co-admin1')

答案 1 :(得分:0)

SELECT * from table 
WHERE (CASE Assignedbyuser = 'co-admin1' THEN Assignedbyuser = 'co-admin1' CASE WHEN  Assignedbyuser != 'co-admin1' THEN  Approve = 1 END) 

试试这个。

答案 2 :(得分:0)

您可以在.........

中使用案例语句
WHERE CASE WHEN AssignedByUser <> 'co-admin1' THEN Approve = 1
ELSE AssignedByUser = 'co-admin1' END

答案 3 :(得分:0)

  

只有Approve = 1但是如果Assignedbyuser =&#39; co-admin1&#39;不要检查Approve = 1

目前尚不清楚。我怀疑你想要:

$(function(){


$.ajax({
            type: "GET",
            url: 'http://XXX:8080/',
            dataType:'json',
            contentType:"application/json",
            success:function(data){
                console.log(data);
                var projectList="<ul style='list-style:none;'>"

                for (var i = 0; i < data.data.length; i++) {

                        projectList += "<li><div id='listall'><a href='/projectDetail'>"+ 
                          "<img class='back' src='data.data[i]'></li>"
                }
             var projectList +="</ul>"

            },
            error:function(){
                    alert("connection error");
            }
}); 



    $('#listall').on('click', 'a', function (){
            console.log('click!');
            alert("finally");
    });
});

了解两种SQL where Assignedbyuser='co-admin1' or Approve = 1 表达式,它们与其他编程语言的case表达式类似。还有涉及&#34;如果&#34;在他们的名字和/或定义中。