我遇到了MYSQL的问题。 SQL_CALC_FOUND_ROWS和FOUND_ROWS()无法正常工作。
问题:
MYSQL版本:
mysql Ver 14.14 Distrib 5.7.10,for osx10.9(x86_64)using EditLine wrapper
我正在尝试从表中返回一个列表,并且该列表中的另一列将针对每一行重复。 (包含select的总行数)。
这样我可以在一个选择中获取所有数据和总行数...
选择在下面。
SELECT SQL_NO_CACHE SQL_CALC_FOUND_ROWS * FROM
(SELECT A.MEMBER_ID, A.USERNAME, B.ZIP, B.INTERESTS, C.ADDRESS
FROM MEMBER A, DATA B, ADDRESS C
WHERE A.GENDER = "F"
AND A.MEMBER_ID = B.MEMBER_ID
AND A.MEMBER_ID = C.MEMBER_ID
AND UPPER (A.CANCEL_FLAG) = "N"
ORDER BY A.LAST_LOGIN_DATE DESC ) res,
(select FOUND_ROWS() as "total_result" from dual ) tot
Limit 1, 15
答案 0 :(得分:2)
如果你想在mysql中使这个工作,你可以使用COUNT
做一个子查询。如果您可以假设MEMBER
和MEMBER_ID
中始终存在DATA
,则可以通过仅计算ADDRESS
表来简化此操作。
SELECT * FROM (
SELECT A.MEMBER_ID, A.USERNAME, B.ZIP, B.INTERESTS, C.ADDRESS
FROM MEMBER A, DATA B, ADDRESS C
WHERE A.GENDER = "F"
AND A.MEMBER_ID = B.MEMBER_ID
AND A.MEMBER_ID = C.MEMBER_ID
AND UPPER (A.CANCEL_FLAG) = "N"
ORDER BY A.LAST_LOGIN_DATE DESC
) res, (
SELECT COUNT(*) as "total_result"
FROM MEMBER A
JOIN DATA B ON A.MEMBER_ID = B.MEMBER_ID
JOIN ADDRESS C ON A.MEMBER_ID = C.MEMBER_ID
WHERE A.GENDER='F'
) tot
LIMIT 1, 15
有关这是否可怕的讨论,请参阅https://www.percona.com/blog/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/。
答案 1 :(得分:0)
确定。我想通了..
我正在使用存储过程。
我刚做了第二次选择。 选择FOUND_ROWS()作为' total_result'来自双重;
这返回了正确的值。
由于 菲尔