分组组

时间:2017-09-19 08:26:19

标签: sql oracle

鉴于下一个表格:

+---+------------+-----------------------------+
|  ID |     A      |      B      |  C          |
+-----+------------+-------------+-------------+
| 1   | TRUE       | FALSE       |   123       |
| 2   | FALSE      | FALSE       |   123       |
| 3   | FALSE      | FALSE       |   123       |  
| 4   | FALSE      | FALSE       |   222       |
| 5   | TRUE       | FALSE       |   222       |  
| 6   | FALSE      | FALSE       |   222       |
| 7   | FALSE      | FALSE       |   333       |  
| 8   | FALSE      | TRUE        |   333       |
| 9   | FALSE      | TRUE        |   444       |  
| 10  | FALSE      | FALSE       |   444       |
+-----+------------+-------------+-------------+
  1. 按C列分组,此组中只能有一个 TRUE ,A或B列中的值 - 获取ID。
  2. 如果A中不存在 TRUE 值,请带上B - 获取ID
  3. 此处所需的输出将是:

    +-----+------------+-------------+-------------+
    |  ID |     A      |      B      |  C          |
    +-----+------------+-------------+-------------+
    | 1   |    TRUE    | FALSE       |   123       |
    | 5   |    TRUE    | FALSE       |   222       |
    | 8   |   FALSE    | TRUE        |   333       |
    | 9   |   FALSE    | TRUE        |   444       |  
    +-----+--------------------------+-------------+
    

    感谢您的帮助

2 个答案:

答案 0 :(得分:1)

您想要显示AB'TRUE'的记录吗?这有什么困难?

select * from mytable where a = 'TRUE' or b = 'TRUE' order by c;

答案 1 :(得分:0)

我想您希望在<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <android.support.design.widget.BottomNavigationView android:id="@+id/navigation" android:layout_width="match_parent" android:layout_height="56dp" android:background="?android:attr/windowBackground" android:backgroundTint="@color/colorPrimary" app:itemBackground="@color/colorPrimary" app:itemIconTint="@color/nav_item_color_state" app:itemTextColor="@android:color/black" app:menu="@menu/navigation" > </android.support.design.widget.BottomNavigationView> <android.support.design.widget.FloatingActionButton android:id="@+id/tools" android:layout_width="56dp" android:layout_height="56dp" android:layout_gravity="center" android:layout_marginBottom="8dp" android:elevation="6dp" android:layout_anchor="@id/navigation" android:layout_anchorGravity="top|center" android:scaleType="center" app:srcCompat="@drawable/play" /> </LinearLayout> A之间实现优先级。试试BNOT EXISTS

UNION ALL