2016-11-12 95 views
0

我有一個表數據爲波紋管相同的信息:在選擇特定的行,如果我有

+--------+----------+-------+------------+--------------+ 
| month | code | type |  date  | PersonID | 
+--------+----------+-------+------------+--------------+ 
| 201501 | 178954 |  3 | 2014-12-3 |   10 | 
| 201501 | 178954 |  3 | 2014-12-3 |   10 | 
| 201501 | 178955 |  2 | 2014-12-13 |   10 | 
| 201501 | 178955 |  2 | 2014-12-13 |   10 | 
| 201501 | 178956 |  2 | 2014-12-11 |   10 | 
| 201501 | 178958 |  1 | 2014-12-10 |   10 | 
| 201501 | 178959 |  2 | 2014-12-12 |   15 | 
| 201501 | 178959 |  2 | 2014-12-12 |   15 | 
| 201501 | 178954 |  1 | 2014-12-11 |   13 | 
| 201501 | 178954 |  1 | 2014-12-11 |   13 | 
+--------+----------+-------+------------+--------------+ 

在我第6行,我有同樣是PersonID同月我想如果我在相同PERSONID同月我想選擇誰擁有類型爲2最近日期在我的情況下,輸出會像波紋管的人:

+--------+--------+------+------------+----------+ 
| month | code | type| date  | PersonID | 
+--------+--------+------+------------+----------+ 
| 201501 | 178955 | 2 | 2014-12-13 |  10 | 
| 201501 | 178959 | 2 | 2014-12-12 |  15 | 
| 201501 | 178954 | 2 | 2014-12-11 |  13 | 
+--------+--------+------+------------+----------+ 

如果他們也有一些重複行我不想顯示它

他們的任何解決方案是什麼?

回答