我有一个表,其中包含了用户设置了最小年龄和最大年龄的用户。
表如下所示:
=========================================
| id | username | age | minAge | maxAge |
=========================================
| 1 | Clark | 20 | 16 | 50 |
-----------------------------------------
| 2 | Kent | 33 | 22 | 25 |
-----------------------------------------
| 3 | Bruce | 45 | 18 | 25 |
-----------------------------------------
| 4 | Wayne | 40 | 23 | 45 |
-----------------------------------------没有人会看到‘肯特’,因为没有人在他的可见范围内。
像这样的东西会怎么样?
我看过这样的事情:
SELECT * FROM table_user WHERE age BETWEEN '16' AND '50';但这当然是另一回事。
发布于 2015-02-26 11:22:45
这是年龄列上的join,使用between (或类似的逻辑)。目前的挑战是如何使这些表按正确的顺序排列:
select u.username, group_concat(tosee.user_name) as users_seen
from table_user u left join
table_user tosee
on tosee.age between u.minage and u.maxage and
tosee.username <> u.username
group by u.username;https://stackoverflow.com/questions/28739490
复制相似问题