2015-09-27 67 views
-2

我有一個包含以下數據的Mysql表。有條件的Mysql select查詢

|ID | Date  | BillNumber|BillMonth | Amount | Name  |AccNum | 
| 2 |2015-09-25| 454345 | 092015 | 135.00 |Andrew Good| 735976| 
| 3 |2015-09-26| 356282 | 092015 | 142.00 |Peter Pan | 123489| 
| 4 |2015-08-11| 312738 | 082015 | 162.00 |Andrew Good| 735976| 
| 5 |2015-07-12| 287628 | 072015 | 220.67 |Andrew Good| 735976| 
| 6 |2015-06-12| 100756 | 062015 | 556.34 |Andrew Good| 735976| 

我想要實現的是與AccNum 735976爲092015的BillMonth檢索安特佳的數據,提供了用戶可以在他BillNumber進入任何(過去/電流)。

+0

你的問題真的沒有感。你爲什麼要這個特定的記錄? –

回答

0

如果該行感興趣的原因是因爲它是最新的他行,請嘗試:

select * 
from tbl t 
where name = ( select name 
        from  tbl 
        where billnumber = 100756 -- can be any of his 
       ) 
    and date = ( select max(date) 
        from  tbl x 
        where x.name = t.name 
       ) 

(該billnumber可以是任何他)