我使用光标分页并希望像这样显示我的数据:
在底部,您可以转到第 1 页到第 29 页。要计算我的页数,我必须计算所有行。每次计算所有行是否很麻烦?是否有其他解决方案,或者我无法摆脱计算所有行的做法?
我也不使用偏移量,那么如何使用光标分页来实现呢?
SELECT
wp.id,
wp.updated_wst,
u.id as user_id, u.firstname, u.lastname,
c.id as company_id, c.company,
wst.id as wst_id,
wst.start_time,
wst.end_time,
wst.send_start_at,
wst.send_end_at,
wst.accepted_by,
wst.accepted_at,
l.name as location
FROM workers_plan wp
LEFT JOIN users u
ON u.id = wp.user_id
LEFT JOIN clients c
ON c.id = u.company_id
LEFT JOIN workers_send_times wst
ON wst.workers_plan_id = wp.id
LEFT JOIN location_orders lo
ON lo.id = wp.location_orders_id
LEFT JOIN location l
ON l.id = lo.location_id
WHERE lo.id = $1 AND wp.tenant_id = $2 AND (wp.id, wp.updated_wst) > ($3, $4)
GROUP BY wp.id, wst.id, u.id, c.id, l.name
ORDER BY wp.id, wp.updated_wst LIMIT 50
这是我当前的代码。但要显示页面,我必须先计算行数,然后计算。我该怎么做(性能最佳的方法)?