我有下表
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/corner_shape"
android:orientation="vertical">
<TextView
android:id="@+id/tvCaption"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="-5dp"
android:background="@drawable/upper_corner"
android:gravity="center"
android:text="@string/heading_order_reroute_page_title"
android:textColor="@android:color/white"
android:textSize="@dimen/heading_text_size"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/label_current_destination"
android:textSize="@dimen/caption_text_size"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_weight="0.1"
android:contentDescription="@drawable/star"
android:src="@drawable/star"
android:visibility="invisible"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvCurrentDestination"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="5dp"
android:layout_weight="3"
android:focusable="false"
android:gravity="start|center_vertical"
android:paddingStart="10dp"
android:textSize="@dimen/caption_text_size"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:gravity="center_vertical"
android:text="@string/label_new_destination"
android:textSize="@dimen/caption_text_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_weight="0.1"
android:contentDescription="@drawable/star"
android:src="@drawable/star" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:layout_height="wrap_content">
<Spinner
android:id="@+id/spinDestination"
style="@android:style/Widget.Spinner"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="5dp"
android:dropDownHorizontalOffset = "?"
android:dropDownVerticalOffset = "?"
android:background="@drawable/bg_edit_text"
android:gravity="start|center_vertical"
android:paddingStart="10dp"
android:spinnerMode="dropdown" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider_color" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:gravity="center_vertical"
android:text="@string/label_reroute_notes"
android:textSize="@dimen/caption_text_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_weight="0.1"
android:contentDescription="@drawable/star"
android:src="@drawable/star" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:layout_height="wrap_content">
<EditText
android:id="@+id/etRerouteNotes"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_margin="5dp"
android:background="@drawable/bg_edit_text"
android:gravity="top|start"
android:paddingStart="10dp"
android:inputType="textMultiLine"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:textSize="@dimen/edit_text_size" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider_color" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btnReroute"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/btn_forward"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="@string/btn_complete_order_reroute_caption"
android:textColor="@android:color/white"
android:textSize="@dimen/button_text_size"
android:textStyle="bold" />
<Button
android:id="@+id/btnCancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/btn_reject"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="@string/btn_cancel_caption"
android:textColor="@android:color/white"
android:textSize="@dimen/button_text_size"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
TABLE store
我想从每个不同的商店返回4级的数量 我知道我可以
store name level
1 Tom 4
2 Joe 2
1 Chris 4
3 Tom 2
4 Ed 2
2 Tom 4
3 Chris 2
要获得独特的商店和
select distinct store from store;
获取4级的计数
如何结合起来以在每个不同的商店中返回4级数量的查询 所以上面的数据会返回
select count(*) as level from store where level = 4;
答案 0 :(得分:1)
不清楚为什么您的表被称为store
。您不应该有一个名字每个商店只有一行的表吗?
在任何情况下,获取0
计数的最简单方法可能是条件聚合:
select store, sum(level = 4) as level4
from store
group by store;