[英]how to select a column from one table according to another table column?
I have 2 tables 'users' and 'criteria'. 我有2个表'用户'和'标准'。
users 用户
------------------------------
username, age, height, country
------------------------------
criteria 标准
-----------------------------------------------------------
username, age_from, age_to, height_from, height_to, country
-----------------------------------------------------------
I want to write a query that 'users' age between 'age_from' and 'age_to' 我想写一个'用户'年龄介于'age_from'和'age_to'之间的查询
AND 和
'users' 'height' between 'height_from' and 'height_to' 'height_from'和'height_to'之间的'用户''身高'
SELECT u.*
FROM Users AS u
INNER JOIN criteria AS c ON u.hiehgt BETWEEN c.height_from
AND c.height_to
AND u.age BETWEEN c.age_from
AND c.age_to;
You might also need to use OUTER JOIN
instead of INNER JOIN
to get those unmatched rows, see this for more information: 您可能还需要使用
OUTER JOIN
而不是INNER JOIN
来获取那些不匹配的行,有关详细信息,请参阅此处:
Try: 尝试:
SELECT u.*
FROM users u
INNER JOIN criteria c
WHERE u.age BETWEEN c.age_from AND c.age_to
AND u.height BETWEEN c.height_from AND c.height_to;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.