如何跳过SQL中的特定行

时间:2015-08-04 10:52:51

标签: mysql

我的数据库中有一个表格,如下所示:

where id = login_id

我希望在比较产品后显示结果:(比较第1和第2分支的产品)

+-------------+---------+--------+
| ProductName | Status  | Branch |
+-------------+---------+--------+
| P1          | dead    |      1 |
| P1          | dead    |      2 |
| P2          | expired |      1 |
| P3          | expired |      3 |
+-------------+---------+--------+

但是在我运行以下查询之后:

+-------------+---------+--------+
| ProductName | Branch 1|Branch 2|
+-------------+---------+--------+
| P1          | dead    |    dead|
| P2          | expired |    OK  |
+-------------+---------+--------+

我得到的结果如下:

<pre>
SELECT  ProductName,
MAX(CASE 
WHEN Branch=1 
THEN Status
ELSE NULL 
END) AS 'Branch 1',
MAX(CASE 
WHEN Branch=2
THEN Status
ELSE NULL 
END) AS 'Branch 2'
FROM    MyTable
GROUP BY ProductName;

SQLFiddle
我想要的是不要在表格中包含除分支1或2以外的产品。谢谢

1 个答案:

答案 0 :(得分:1)

使用<fragment android:name="com.covle.hellocarson.SomeFragment" android:layout_width="wrap_content" android:layout_height="wrap_content"/>

过滤您的查询结果
<fragment
    android:id="@+id/some_fragment"
    android:name="com.covle.hellocarson.SomeFragment"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

DEMO