mysql SELECT id bank_id MAX first_payment from banks WHERE first_payme

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mysql> SELECT id,bank_id,MAX(first_payment) from banks WHERE first_payment <= 50 GROUP BY bank_id
-> ;
+----+---------+--------------------+
| id | bank_id | MAX(first_payment) |
+----+---------+--------------------+
| 3 | 1 | 30 |
| 1 | 2 | 50 |
| 5 | 3 | 50 |
+----+---------+--------------------+
3 rows in set (0.05 sec)
mysql> select * from banks;
+----+---------+---------------+
| id | bank_id | first_payment |
+----+---------+---------------+
| 1 | 2 | 10 |
| 2 | 2 | 20 |
| 3 | 1 | 30 |
| 4 | 1 | 10 |
| 5 | 3 | 10 |
| 6 | 3 | 50 |
| 7 | 2 | 50 |
+----+---------+---------------+
7 rows in set (0.00 sec)