我有一个数据库情况,我希望按用户年龄范围获取用户个人资料行。
这是我的db:
table_users
username age email url
pippo 15 example@example.com http://example.com
pluto 33 example@example.com http://example.com
mikey 78 example@example.com http://example.com
table_profiles
p_name start_age_range stop_age_range
young 10 29
adult 30 69
old 70 inf
我使用MySQL
和PHP
但我不知道是否有一些特定的tacnique来做这件事,当然,如果可能的话。
# so something like:
SELECT *
FROM table_profiles AS profiles
INNER JOIN table_users AS users
# can I do something like this?
ON users.age IS BETWEEN profiles.start_age_range AND profiles.stop_age_range
答案 0 :(得分:2)
Select
*
From
table_profiles As profiles,
table_users As users
Where
users.age Between profiles.start_age_rage And profiles.stop_age_range
答案 1 :(得分:0)
怎么样?
SELECT *
FROM table_profiles AS profiles
Where
users.age >= profiles.start_age_range AND users.age <=profiles.stop_age_range