firebird中FOUND_ROWS()的功能是什么? [英] whats the same function of FOUND_ROWS() in firebird?
问题描述
亲爱的所有...我熟悉MySQL,但不熟悉Firebird.
dear all...i'm familiar with MySQL but not with Firebird.
我想将我的PHP页面从MySQL更改为Firebird query.但是在更改命令FOUND_ROWS()
时遇到了一些困难.有人知道Firebird中FOUND_ROWS()的功能是什么吗?
i want to change my php page, from MySQL into Firebird query.But i got some difficulty during change command FOUND_ROWS()
. is there someone who know whats the same function of FOUND_ROWS() in Firebird?
我浏览了每个站点,但没有答案.我被困在这种情况下.请帮忙.
i have browsed in every sites but i have no answer. i'm stuck in this case.please help.
推荐答案
类似于@Andrei K.答案.
Similar to @Andrei K. answer.
您的问题的答案:Firebird中的FOUND_ROWS()MySQL函数/语句没有等效项.
Answer to your question: There's no equivalent in Firebird for FOUND_ROWS() MySQL function/statement.
解决方法:如果您非常想知道该行数,请要求引擎运行一个新查询以计算针对第一个查询的特殊版本的行数.对于简单查询, @Andrei K.答案是准确的,但在一般情况下,包括带有group by并具有条款的查询都使用类似这样的查询:
Workaround: If you deadly want to know that number of rows, ask the engine to run a new query to compute the number of rows present for a special version of the first query. For simple queries, @Andrei K. answer is accurate, but for the general case, including queries with group by and having clauses use a query like this:
select count(*)
from (your original query here) q1;
如果原始查询中存在first/skip和order by子句,则必须将其排除在外.因此,对于查询如下:
You have to exclude the first/skip and order by clauses if present in that original query. So, for a query looking this:
select first 10 skip 20 pd.productcode, extract(year from ph.purchasedate) year, sum(pd.quantity) year_quantity
from purchase_details pd
inner join purchase_header ph
on ph.id = pd.purchase_id
where ph.cancelled = 0
and ph.salesman = 10
group by pd.productcode, extract(year from ph.purchasedate)
having sum(pd.quantity) > 1000
order by sum(pd.quantity) desc;
found_rows等效查询将为:
the found_rows equivalent query will be:
select count(*)
from (
select pd.productcode, extract(year from ph.purchasedate) year, sum(pd.quantity) year_quantity
from purchase_details pd
inner join purchase_header ph
on ph.id = pd.purchase_id
where ph.cancelled = 0
and ph.salesman = 10
group by pd.productcode, extract(year from ph.purchasedate)
having sum(pd.quantity) > 1000
) q1
根据我的经验,此方法适用于99.9%的查询.
From my experience, this works for 99.9% of the queries.
警告:这种方法效率很低,使用风险自负.
Warning This approach is very inefficient, use at your own risk.
这篇关于firebird中FOUND_ROWS()的功能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!