Select category,
concat(count(category) * 100/ (select count(*) from table3),'%') as category_percentage_males
from table3
where gender in ('m')
group by category
order by category_percentage_males desc
由于某种原因,一旦我结束,订单不会返回desc。没有concat订单工作正常。为什么会发生这种情况的任何原因?
答案 0 :(得分:1)
这是您的查询:
Select category, concat(count(category) * 100/ (select count(*) from table3),'%') as category_percentage_males
from table3 where gender in ('m')
group by category
order by category_percentage_males desc;
我强烈建议您将其作为:
Select category,
concat(avg(case when gender = 'm' then 100.0 else 0 end), '%') as category_percentage_males
group by category
order by avg(case when gender = 'm' then 100.0 else 0 end) desc;