MySQL where 查询不能使用别名的解决方法

select * from (SELECT sheng.prov_name,shi.city_name,qu.cnty_name,us.`school_name`, (SELECT COUNT(uu.user_id) FROM u_user uu JOIN `u_user_role` uur ON uu.user_id = uur.`user_id` JOIN `u_classes_user` ucu ON uu.user_id = ucu.user_id JOIN `u_classes` uc ON ucu.`classes_id` = uc.classes_id JOIN `u_school_grade` usg ON uc.`school_grade_id` = usg.`school_grade_id` WHERE uu.user_name LIKE 'lyο%' AND us.school_name IS NOT NULL AND usg.`school_id` = us.`school_id` AND uur.role_id = '38') user_student FROM `u_school` us JOIN u_distcd qu ON us.`dist_cd` = qu.`dist_cd` JOIN u_distcd shi ON qu.`p_dist_cd` = shi.`dist_cd` JOIN u_distcd sheng ON shi.`p_dist_cd` = sheng.dist_cd) as a where user_student > 0 ;

外面包一层,就可以了。

你可能感兴趣的:(mysql)