我有这个SQL查询:
select GEN_source, count(*) as count, sum(100) / total as percentage
from tics
cross join (select count(*) as total from t_cs) x
group by 1
如何在同一查询中使用创建的别名添加order by count ASC
?
感谢。
答案 0 :(得分:0)
Count是一个保留字,因此需要将其封装在背景上或更改名称
select GEN_source, count(*) as `count`, sum(100) / total as percentage
from tics
cross join (select count(*) as total from t_cs) x
group by 1
ORDER By `count`
或
select GEN_source, count(*) as cnt, sum(100) / total as percentage
from tics
cross join (select count(*) as total from t_cs) x
group by 1
ORDER By cnt