mysql查询,否则无法正常工作

时间:2015-07-08 09:26:04

标签: php mysql mysqli

在我的查询中,我想添加另一个条件

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/AppTheme.TranslucentWindow">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/drawer_header"
        app:itemTextColor="@android:color/black"
        app:menu="@menu/drawer_menu" />

</android.support.v4.widget.DrawerLayout>

这是我的完整查询

if((select ShowMan from preferences where `UserId`='92') == true )
 then users.gender !='female'

我的逻辑isifuser 92 ShowMan值为true然后添加条件users.gender!=&#39; female&#39; 如果ShowMan值为false,则添加条件users.gender!=&#39; male&#39;

1 个答案:

答案 0 :(得分:0)

将最后一部分更改为此工作:

and ((NOT (select ShowMan from preferences where `UserId`='92')) OR (users.gender !='female'))

或者这是完整的查询

SELECT 'users'.*
FROM `users`
JOIN preferences ON `UserID` = users.id
WHERE users.id != '92' AND
  users.id NOT IN (SELECT matched_user_id
                   FROM `user_matchs`
                   WHERE user_id = users.id
                  )
AND   users.id NOT IN (SELECT user_id
                   FROM `user_matchs`
                   WHERE matched_user_id = users.id
                   AND status = 'friend'
                  ) 
AND ((NOT `preferences`.`ShowMan`) OR (users.gender !='female'))