我有一個查詢返回操作的信用票據(CN)和借項通知(DN),每個CN附帶有兩個或多個DN(由字段payment_plan_id
引用)。在分頁時,例如我必須帶10個操作,即10個CN和他們的DN,但是如果我將限制保留在10,它也將計算我必須在查詢中返回的事務的借方記錄。所以,它只會帶來2,3或4次操作,具體取決於信用票據附帶的DN的數量。表排除某些領域的應用限制爲條件
SELECT
value, installment, payment_plan_id, model,
creation_date, operation
FROM payment_plant
WHERE model != 'IMMEDIATE'
AND operation IN ('CN', 'DN')
AND creation_date BETWEEN '2017-06-12' AND '2017-07-12 23:59:59'
ORDER BY
model,
creation_date,
operation
LIMIT 10
OFFSET 1
例子:
| id | payment_plan_id | value | installment | operation |
---------------------------------------------------------
| 1 | b3cdaede | 12 | 1 | NC |
| 2 | b3cdaede | 3.5 | 1 | ND |
| 3 | b3cdaede | 1.2 | 1 | ND |
| 4 | e1d7f051 | 36 | 1 | NC |
| 5 | e1d7f051 | 5.9 | 1 | ND |
| 6 | 00e6a0b4 | 15 | 1 | NC |
| 7 | 00e6a0b4 | 1 | 1 | ND |
| 8 | 00e6a0b4 | 3.6 | 1 | ND |
如何限制的限制,使其只考慮NC的?
您按「SELECT」中未包含的列進行排序。這似乎很奇怪。 –