php如何输出表格内容比较快捷高效。
[解决办法]
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
Array输出时需对 constitute 列做一下处理
(
[0] => Array
(
[fenlei] => 北京
[count(*)] => 2
[percentage] => 25.0000
[constitute] => 服务好,1,卫生好,1
)
[1] => Array
(
[fenlei] => 上海
[count(*)] => 4
[percentage] => 50.0000
[constitute] => 服务好,2,卫生好,2
)
[2] => Array
(
[fenlei] => 天津
[count(*)] => 2
[percentage] => 25.0000
[constitute] => 服务好,1,卫生好,1
)
)