sphinxql如何得到结果数及show meta的详细说明
2013-02-07 00:00
417 查看
mysql:
select count(*) from main_index;
但是这个在这里却报语法错误。
第一种方法:
查文档得:
Aggregate functions (***G(), 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(*),如:
第二种方法
也就是说用show meta来得到这个total_found,这个就是总记录数。
下面我们来说一下show meta:
SHOW META shows additional meta-information about the latest query such as query time and keyword statistics:
也就是说它显示的是最近一次查询附加的一些信息,比如查询时间、关键字统计、总记录等。
在PHP中如何调用?
注意:如果代码中用了多个数据库连接的话,这个相应的conn必须传进来,否则是取不到结果的。
select count(*) from main_index;
但是这个在这里却报语法错误。
第一种方法:
查文档得:
Aggregate functions (***G(), 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,这个就是总记录数。
下面我们来说一下show meta:
SHOW META shows additional meta-information about the latest query such as query time and keyword statistics:
也就是说它显示的是最近一次查询附加的一些信息,比如查询时间、关键字统计、总记录等。
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必须传进来,否则是取不到结果的。
相关文章推荐
- sphinxql如何得到结果数及show meta的详细说明
- 如何得到SQL Server2000的结果集中行的行号
- InnoDB -- innodb表如何更快得到count(*)结果
- 如何在ALV中得到对字段有效性检查的结果.
- 网站如何上百度首页,详细说明,
- Mapreduce读取和写入Hbase(从A表读取数据,统计结果放入B表,非常详细,附有代码说明以及流程)
- meta 标签 详细说明
- Nginx如何实现支持HTTPS协议详细说明
- cmd中如何得到另外一个命令的结果
- CreateUserWizard控件的详细使用说明(如何使用CreateUserWizard控件)
- 装饰者模式的学习(c#) EF SaveChanges() 报错(转载) C# 四舍五入 保留两位小数(转载) DataGridView样式生成器使用说明 MSSQL如何将查询结果拼接成字符串 快递查询 C# 通过smtp直接发送邮件 C# 带参访问接口,WebClient方式 C# 发送手机短信 文件 日志 写入 与读取
- 很详细的说明了如何 在2000和2005下进行行列置换
- Excel 如何把运算表达式,进行运算得到结果
- [InnoDB系列] -- innodb表如何更快得到count(*)结果
- MySQL中show 句法得到表列及整个库的详细信息
- HTML meta viewport属性详细说明
- Git学习-->如何通过Shell脚本实现 监控Gitlab备份整个过程并且通过邮件通知得到备份结果?
- 如何判断ExecuteScalar()得到的结果是否有记录
- 如何得到QML package的详细API接口
- MySQL中show命令方法得到表列及整个库的详细信息(精品珍藏)