borrow_id borrower_id book_id borrow_date expected_return_date
1 19 6 0000-00-00 0000-00-00
2 1 10 0000-00-00 0000-00-00
3 20 1 0000-00-00 0000-00-00
4 18 3 2016-04-30 2016-05-02
5 19 8 2016-04-30 2016-05-03
6 21 7 2016-04-30 2016-05-03
7 22 14 2016-01-05 0000-00-00
8 13 1 2016-05-02 2016-06-04
9 18 3 2016-06-02 2016-05-26
12 23 14 2016-06-02 2016-05-03
13 1 5 2016-05-02 0000-00-00
14 23 1 2016-05-02 2016-05-03
这是我的桌子。对于borrower_id列的相同值,我想要一个更大的borrow_id。例如,有两次borrower_id 19。我想借用5行而不是借用1行作为5> 1。
对此的查询是什么?
答案 0 :(得分:3)
你可以使用
中的subselect grop select * from my_table
where (borrow_id, borrower_id) in (select max(borrow_id), borrower_id
from my_table group by borrower_id);
答案 1 :(得分:0)
select * from borrow where borrow_id =
(select max(borrow_id) from borrow where borrower_id=19)