带有多个语句的mysql多个查询

时间:2018-03-16 15:58:04

标签: mysql sql

我编写了一个查询,它返回我的下线的用户名,并根据(引用更多下线的用户)对它们进行排序 这是查询。

SELECT user_name FROM users u 
WHERE referby='$competitionmaker'
ORDER BY (select count(p.user_id) from users p where u.user_name=p.referby) 
DESC LIMIT 10

工作正常。但我想要的东西。 我想选择只有那些推荐超过5个人的人的下线用户名。我该怎么做? 我能用这个吗?

mysqli_query($con,"SELECT user_name from users u where referby='$usern' AND
(select count(p.user_id) from users p where u.user_name=p.referby)>0 ORDER BY
(select count(p.user_id) from users p where u.user_name=p.referby) DESC LIMIT 10")

还是有其他想法吗?

0 个答案:

没有答案
相关问题