Mysql应用sphinxql如何得到结果数及show meta的详细说明

Mysql应用sphinxql如何得到结果数及show meta的详细说明,第1张

概述介绍《Mysql应用sphinxql如何得到结果数及show meta的详细说明》开发教程,希望对您有用。

《MysqL应用sphinxql如何得到结果数及show Meta的详细说明》要点:
本文介绍了MysqL应用sphinxql如何得到结果数及show Meta的详细说明,希望对您有用。如果有疑问,可以联系我们。

MysqL:
select count(*) from main_index;MysqL数据库

但是这个在这里却报语法错误.MysqL数据库

第一种办法:
查文档得:
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.MysqL数据库

也就是说只有在group by的时候才能用count(*),如:MysqL数据库

代码如下:
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,这个就是总记录数.

下面我们来说一下show Meta:
SHOW Meta shows additional Meta-information about the latest query such as query time and keyword statistics:MysqL数据库

也就是说它显示的是最近一次查询附加的一些信息,好比查询时间、关键字统计、总记录等.
MysqL数据库

代码如下:
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中如何调用?
代码如下:
<?PHP
//获取总记录个数
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;
}
?>

注意:如果代码中用了多个数据库连接的话,这个相应的conn必需传进来,否则是取不到结果的.

《MysqL应用sphinxql如何得到结果数及show Meta的详细说明》是否对您有启发,欢迎查看更多与《MysqL应用sphinxql如何得到结果数及show Meta的详细说明》相关教程,学精学透。内存溢出 jb51.cc为您提供精彩教程。

总结

以上是内存溢出为你收集整理的Mysql应用sphinxql如何得到结果数及show meta的详细说明全部内容,希望文章能够帮你解决Mysql应用sphinxql如何得到结果数及show meta的详细说明所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/sjk/1155563.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存