国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MySQL > 正文

sphinxql如何得到結(jié)果數(shù)及show meta的詳細(xì)說明

2024-07-24 13:01:07
字體:
供稿:網(wǎng)友

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(*),如:

復(fù)制代碼 代碼如下:


select 1 as dummy,count(*) c from main_index group by dummy;
+------+--------+-------+--------+
| id | weight | dummy | @count |
+------+--------+-------+--------+
| 1001 | 1| 1 | 15659 |
+------+--------+-------+--------+


第二種方法

復(fù)制代碼 代碼如下:


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)計、總記錄等。

復(fù)制代碼 代碼如下:


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)用?

復(fù)制代碼 代碼如下:


<?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必須傳進來,否則是取不到結(jié)果的。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 榆林市| 清徐县| 乌拉特中旗| 正宁县| 汝阳县| 和顺县| 武冈市| 莎车县| 七台河市| 黄龙县| 大埔县| 旬邑县| 钦州市| 巴中市| 武汉市| 梁平县| 莱芜市| 明光市| 卢龙县| 双桥区| 新昌县| 潞城市| 邵东县| 册亨县| 景宁| 盐山县| 桐城市| 沁阳市| 防城港市| 察哈| 疏附县| 德兴市| 含山县| 文安县| 武功县| 石景山区| 略阳县| 东兰县| 雷山县| 武隆县| 资溪县|