Php outputs table content quickly and efficiently. At the end of this post, phpcainiao edited php on 2013-09-0612: 03: 08 to output table content quickly and efficiently. For example, I now have a test table. Id, fenlei, and mc are represented respectively, id, automatic growth, fenlei, and mc in the participating regions. the specific selection parameter id & nbsp; & how php outputs table content is quick and efficient.
This post was last edited by phpcainiao at 12:03:08
Php outputs table content quickly and efficiently.
For example, I now have a test table.
There are IDs, fenlei, mc
Id, automatic growth,
Fenlei, participating regions
Mc, specific selection parameters
Id fenlei mc
1 Beijing health care
2 Shanghai health care
3. good service in Shanghai
4 Tianjin health care
5. good service in Tianjin
6. good service in Beijing
7 Shanghai health care
8. good service in Shanghai
I want to make a statistics on this table .. Use the program to output the following table.
I want to separate statistics
Share:
------ Solution --------------------
select a.fenlei, count(*), count(*)/(select count(*) from test)*100 as percentage, constitute
from test a, (select fenlei, group_concat(mc,',',cnt) as constitute from
(select fenlei, mc, count(*) as cnt from test group by 1,2) t group by 1) t1
where a.fenlei=t1.fenlei
group by 1
Execute this SQL command to obtain such data
Array
(
[0] => Array
(
[Fenlei] => Beijing
[Count (*)] => 2
[Percentage] = & gt; 25.0000
[Constitute] => good service, 1. good hygiene, 1
)
[1] => Array
(
[Fenlei] => Shanghai
[Count (*)] => 4
[Percentage] = & gt; 50.0000
[Constitute] => good service, 2, good hygiene, 2
)
[2] => Array
(
[Fenlei] => Tianjin
[Count (*)] => 2
[Percentage] = & gt; 25.0000
[Constitute] => good service, 1. good hygiene, 1
)
)
The constitute column must be processed during output.