sphinxql如何得到結(jié)果數(shù)及show meta的詳細(xì)說明
mysql:
select count(*) from main_index;
但是這個在這里卻報語法錯誤。
第一種方法:
查文檔得:
Aggregate functions (AVG(), MIN(), MAX(), SUM()) in column list clause are supported. Arguments to aggregate functions can be either plain attributes or arbitrary expressions. COUNT(*) is implicitly supported as using GROUP BY will add @count column to result set. Explicit support might be added in the future. COUNT(DISTINCT attr) is supported. Currently there can be at most one COUNT(DISTINCT) per query and an argument needs to be an attribute. Both current restrictions on COUNT(DISTINCT) might be lifted in the future.
也就是說只有在group by的時候才能用count(*),如:
select 1 as dummy,count(*) c from main_index group by dummy;
+------+--------+-------+--------+
| id | weight | dummy | @count |
+------+--------+-------+--------+
| 1001 | 1 | 1 | 15659 |
+------+--------+-------+--------+
第二種方法
select * from main_index limit 0;
show meta;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| total | 67 |
| total_found | 67 |
| time | 0.001 |
| keyword[0] | ha |
| docs[0] | 67 |
| hits[0] | 115 |
+---------------+-------+
也就是說用show meta來得到這個total_found,這個就是總記錄數(shù)。
下面我們來說一下show meta:
SHOW META shows additional meta-information about the latest query such as query time and keyword statistics:
也就是說它顯示的是最近一次查詢附加的一些信息,比如查詢時間、關(guān)鍵字統(tǒng)計、總記錄等。
mysql> SELECT * FROM test1 WHERE MATCH('test|one|two');
+------+--------+----------+------------+
| id | weight | group_id | date_added |
+------+--------+----------+------------+
| 1 | 3563 | 456 | 1231721236 |
| 2 | 2563 | 123 | 1231721236 |
| 4 | 1480 | 2 | 1231721236 |
+------+--------+----------+------------+
3 rows in set (0.01 sec)
mysql> SHOW META;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| total | 3 |
| total_found | 3 |
| time | 0.005 |
| keyword[0] | test |
| docs[0] | 3 |
| hits[0] | 5 |
| keyword[1] | one |
| docs[1] | 1 |
| hits[1] | 2 |
| keyword[2] | two |
| docs[2] | 1 |
| hits[2] | 2 |
+---------------+-------+
12 rows in set (0.00 sec)
在PHP中如何調(diào)用?
<?php
//獲取總記錄個數(shù)
private function getTotalFound($conn) {
$sql = "show meta";
$total_result = @mysql_query ( $sql,$conn );
$totals = array ();
while ( ($row = mysql_fetch_assoc ( $total_result )) !== false ) {
$totals [$row ['Variable_name']] = $row ['Value'];
}
return $totals;
}
?>
注意:如果代碼中用了多個數(shù)據(jù)庫連接的話,這個相應(yīng)的conn必須傳進(jìn)來,否則是取不到結(jié)果的。
相關(guān)文章
SQL語句中LEFT JOIN的ON和WHERE有什么區(qū)別
這篇文章主要介紹了SQL語句中LEFT JOIN的ON和WHERE之間的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-12-12MySQL利用procedure analyse()函數(shù)優(yōu)化表結(jié)構(gòu)
不知道是否遇到過為MySQL表結(jié)構(gòu)該選擇什么類型字段而郁悶?或者為MySQL字段該選擇多少長度而糾結(jié)?下面這篇文章就給大家介紹一個武林秘籍吧~也是我最近才學(xué)來的,感興趣的朋友們下面來一起看看吧。2016-12-12windows 安裝解壓版 mysql5.7.28 winx64的詳細(xì)教程
這篇文章主要介紹了windows 安裝解壓版 mysql5.7.28 winx64的詳細(xì)教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12MySQL 線上數(shù)據(jù)庫清理數(shù)據(jù)的方法
這篇文章主要介紹了MySQL 線上數(shù)據(jù)庫清理數(shù)據(jù)的方法,幫助大家更好的理解和學(xué)習(xí)使用MySQL,感興趣的朋友可以了解下2021-03-03MySQL大量臟數(shù)據(jù)如何只保留最新的一條(最新推薦)
這篇文章主要介紹了MySQL大量臟數(shù)據(jù),如何只保留最新的一條,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-04-04