我想实现一个带有分页的表格组件。表中的结果由这样的多选查询检索:
SELECT DISTINCT t0.userId,
t0.userName,
t1.rolleName
FROM userTable t0
LEFT OUTER JOIN roleTable t1 ON t0.userId = t1.fkUser
WHERE(t0.userType = 'normalUser' AND t1.roleType = 'loginRole')
这个结果我可以通过多选查询得到。
现在对于分页,我必须首先检索总行数。有没有人可以为这个 sql 之一定义条件查询?我失败了,因为子查询不支持多选,而且我不知道如何将此不同的内容放入 count 语句中。
SELECT COUNT(*) FROM
(
SELECT DISTINCT t0.userId,
t0.userName,
t1.rolleName
FROM userTable t0
LEFT OUTER JOIN roleTable t1 ON t0.userId = t1.fkUser
WHERE(t0.userType = 'normalUser' AND t1.roleType = 'loginRole')
)
或者
SELECT COUNT(DISTINCT t0.userId || t0.userName || t1.rolleName)
FROM userTable t0
LEFT OUTER JOIN roleTable t1 ON t0.userId = t1.fkUser
WHERE(t0.userType = 'normalUser' AND t1.roleType = 'loginRole')
提前致谢!
顺便提一句。我在 WebSphere AppServer 上使用 OpenJpa