假设我有产品:
folio price quantity
1 100.00 1
1 450.00 2
3 150.00 1
4 600.00 2
条款:(根据产品价格了解多少付款条款)
level term
0.01 12
100.00 14
200.00 16
300.00 18
400.00 20
500.00 22
我该怎么做才能得到这样的结果表:
folio price quantity term
1 100.00 1 14
1 450.00 2 20
我试过使用:
SELECT a.*, b.term
FROM products AS a
JOIN terms AS b ON b.level <= a.price
WHERE a.folio = 1
但我最终得到:
folio price quantity term
1 100.00 1 12
1 100.00 1 14
1 450.00 2 12
1 450.00 2 14
1 450.00 2 16
1 450.00 2 18
1 450.00 2 20
我该怎么做才能只得到最大术语的行?请帮忙!