2014-09-02 48 views
0

所以我存储不同类型的测量在一个名为列值如何使查询在同一列中找到不同的值?

(select count(*) from `lara_measurements` inner join `lara_users_measurement` on `lara_measurements`.`id` = `lara_users_measurement`.`measurement_id` where `lara_users_measurement`.`user_id` = `lara_users`.`id` and `value` between 160 cm and 165 cm and `value` between 46 kg and 52 kg)

但因为这些值使用相同的列,使用不起作用,它仅适用,如果只有一个执行查询之间

我周围搜索了很多,但没有找到任何东西。

有人可以给我一个提示吗?

+0

这甚至不是SQL。你在这里发布什么? – tadman 2014-09-02 18:50:19

+0

“\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ – 2014-09-02 18:56:35

+0

改为使用OR。逻辑上,您无法在值160-165和值46-52之间找到记录。 – 2014-09-02 19:05:27

回答

0

如果我正确地理解了你的问题。尝试:
(select count(*) from `lara_measurements` inner join `lara_users_measurement` on `lara_measurements`.`id` = `lara_users_measurement`.`measurement_id` where `lara_users_measurement`.`user_id` = `lara_users`.`id` and (`value` between 160 cm and 165 cm or `value` between 46 kg and 52 kg))
对不起,如果这是错误的想法,但很难准确地告诉你想要什么。

相关问题