在子查询中使用SQL_CALC_FOUND_ROWS [英] Using SQL_CALC_FOUND_ROWS in a subquery
问题描述
我发现MySQL返回一个
I find that MySQL returns a
Incorrect usage/placement of 'SQL_CALC_FOUND_ROWS'
如果我将SQL_CALC_FOUND_ROWS放在子查询中,则会出错
error if I put SQL_CALC_FOUND_ROWS in a subquery
SELECT
*
FROM
(
SELECT SQL_CALC_FOUND_ROWS * FROM test_table
) as T1
是否有解决方法?还是我实施不正确?
Is there a workaround for this? or am I just implementing it incorrectly?
如果有人想知道的话,我有必要将T1设为子查询是有原因的.
There is a reason why I need to make T1 a subquery in case anyone is wondering.
推荐答案
似乎您使用的方式不正确. SQL_CALC_ROWS_FOUND
似乎仅适用于外部查询.我不确定这是否适合您的用例,或者您的外部查询中是否包含其他WHERE
,但是您可以执行以下操作:
It seems like you're using it incorrectly. The SQL_CALC_ROWS_FOUND
seems to only apply to outer queries. I'm not sure if this would fit your use case, or if you have additional WHERE
s in your outer query, but you may be able to do something like this:
选择 SQL_CALC_FOUND_ROWS * 从 ( SELECT * FROM test_table )作为T1;
SELECT FOUND_ROWS();
SELECT SQL_CALC_FOUND_ROWS * FROM ( SELECT * FROM test_table ) as T1 ;
SELECT FOUND_ROWS();
FOUND_ROWS()
函数将为您提供在应用任何LIMIT
之前找到的总行数.有关FOUND_ROWS()
的更多信息,请在此处.
The FOUND_ROWS()
function will give you the total number of rows found before any LIMIT
s are applied. For more on FOUND_ROWS()
check here.
这篇关于在子查询中使用SQL_CALC_FOUND_ROWS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!