我有这个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
如何在同一查询中使用创建的别名添加按计数 ASC 排序
?
谢谢。
最佳答案
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
关于mysql - 在同一个 sql 查询中使用别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23394682/