0

我有 2 个表“用户”和“标准”。

用户

------------------------------
username, age, height, country
------------------------------

标准

-----------------------------------------------------------
username, age_from, age_to, height_from, height_to, country
-----------------------------------------------------------

我想写一个查询'用户'年龄在'age_from'和'age_to'之间

'height_from' 和 'height_to' 之间的 'users' 'height'

4

2 回答 2

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获取那些不匹配的行,请参阅此以获取更多信息:

于 2013-03-04T10:03:35.280 回答
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;
于 2013-03-04T10:12:21.793 回答