显示mysql数据库的统计信息

时间:2012-09-16 19:23:49

标签: php mysql

我有一个数据库表。它包含以下列:

Cathegory |优先|

是否有完成的脚本或显示这些列的统计信息的方法?

基本上我要做的是显示这些列的统计信息。

例如,

  

导弹可以有不同的值,例如:(大陆,   国家,城市,街道)   优先级可以包含1-10之间的值。

所以我需要显示有多少行,每行显示不同的值。

例如:

4 of the priority 8 rows have 'continent' as catheogry,
43 of the priority 8 rows have 'country' as cathegory,
329 of the priority 8 rows have 'city' as cathegory

这可能吗?

2 个答案:

答案 0 :(得分:2)

没有内置脚本可以为您做到这一点,但当然您可以使用SQL获取所有类型的信息,这是关系数据库的基本思想。

表格中的行数

select count(*) from table;

示例

select cathegory, count(cathegory) nbr_of_cathegories_for_prio_8 from table where priority = 8 group by cathegory;

答案 1 :(得分:0)

在您的示例中:329 of the priority 8 rows have 'city' as cathegory

我认为:

  

8 - 是优先级值     329 - 特定类别的特定优先级重复优先级的时间。

PHP implimentation看起来像:

<?php

$sql = "
       SELECT Priority, COUNT(Priority) as nbr_of_Priorities, cathegory, 
       FROM table_Name
       GROUP BY Priority, cathegory
    ";

$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
         echo $row['nbr_of_Priorities'].'of the priority'.$row[' Priority'];
         echo 'has'.$row['cathegory'].'as catheogry';
}
?>