請問如何取回MYSQL中SELECT FOUND_ROWS()的值? |
缺席
|
pcernet
初階會員 發表:69 回覆:113 積分:41 註冊:2002-11-29 發送簡訊給我 |
SQL語句為
SELECT SQL_CALC_FOUND_ROWS * FROM table1 LIMIT 20 SELECT FOUND_ROWS() //配合SQL_CALC_FOUND_ROWS可以傳回所有的資料筆數,有效率的做法 我使用了Zeos Access的TZQuery控件, zquery1.Close; //zquery1.SQL.Text:='select SQL_CALC_FOUND_ROWS * from table1 limit 20'; zquery1.SQL.clear; zquery1.SQL.add('select SQL_CALC_FOUND_ROWS * from table1 limit 20'); zquery1.Open; 請問,有誰知道要如何做才能取回 FOUND_ROWS() 的值,謝謝! |
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
|
pcernet
初階會員 發表:69 回覆:113 積分:41 註冊:2002-11-29 發送簡訊給我 |
|
pcernet
初階會員 發表:69 回覆:113 積分:41 註冊:2002-11-29 發送簡訊給我 |
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#id2890708
For a SELECT with a LIMIT clause, the number of rows that would be returned were there no LIMIT clause A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS() afterward: 從MySQL4.1開始,「SQL_CALC_FOUND_ROWS」告訴MySQL要將SQL所處理的行數記錄下來,至於「FOUND_ROWS()」則用來取得總資料筆數;若在前一條語句中沒有使用SQL_CALC_FOUND_ROWS的選項,FOUND_ROWS()將返回前一條查詢語句實際返回的行數。 sql_calc_found_rows data limit 20select found_rows(); 只需要造訪資料表一次,非常有效率的做法,只是PHP可以輕易執行,但在Delphi要怎麼下語法呢? 多語句?子查詢? zquery1.close; zquery1.sql.add('Select SQL_CALC_FOUND_ROWS * from data limit 20'); zquery1.open; //zquery1.sql.clear; //zquery1.sql.add('Select FOUND_ROWS()'); 還是沒辦法,持續關注中... |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |