我试图用户通过他们的xp排序,同时从结果中排除管理员。
管理员在表格中rights
列等于2
。
通过xp订购时,更高的声望有更好的排名。
select
a.*,
1 + count(b.username) AS rank
from `hs_users` as `a`
left join `hs_users` as `b`
on
`b`.`prestige` = `a`.`prestige` and `b`.`overall_xp` > `a`.`overall_xp`
or `b`.`prestige` > `a`.`prestige`
and `b`.`rights` <> `2`
where `a`.`rights` <> 2
group by `a`.`username` order by `prestige` desc, `rank` asc
此查询给出了一个名为Unknown column '2' in 'on clause'.
我该如何解决这个问题?
答案 0 :(得分:1)
从数字和字符串中删除背景信息。反引号只是为了逃避列名。 对于转义字符串,您必须使用单个qoutes。 在nubers,没有必要逃脱它们。
select
a.*,
1 + count(b.username) AS rank
from `hs_users` as `a`
left join `hs_users` as `b`
on
`b`.`prestige` = `a`.`prestige` and `b`.`overall_xp` > `a`.`overall_xp`
or `b`.`prestige` > `a`.`prestige`
and `b`.`rights` <> 2
where `a`.`rights` <> 2
group by `a`.`username` order by `prestige` desc, `rank` asc