我有2个表'用户'和'标准'。
用户
------------------------------
username, age, height, country
------------------------------
标准
-----------------------------------------------------------
username, age_from, age_to, height_from, height_to, country
-----------------------------------------------------------
我想写一个'用户'年龄介于'age_from'和'age_to'之间的查询
和
'height_from'和'height_to'之间的'用户''身高'
答案 0 :(得分:2)
JOIN
两个表:
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;
您可能还需要使用OUTER JOIN
代替INNER JOIN
来获取这些不匹配的行,有关详细信息,请参阅此处:
答案 1 :(得分:0)
尝试:
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;