简体   繁体   中英

How to find record which falls inbetween two fields in mysql?

i have two fields in a table jobpost like this:-

jp_id jp_min jp_max
1      0       1
2      1       2
3      3       4
4      4       8
5      2       3
6      0       1
What i'm trying to find out is if i search for a job with experience 5-9 or 1-5 i should get 4rth record. But if i search for 1-3 exp then i shouldn't get the 4rth record.
I had tried out like this :-
 a)SELECT * FROM jobpost WHERE jp_min >=1 AND jp_max <=5;  & \nb)SELECT * FROM jobpost WHERE (jp_min >=1 AND jp_max <=5);  (this one gives result of  \njobpost which requires 1-5 exp only and not that 4rth record 4-8 exp.)  
but it's not giving me the desired results. Can someone give me hint or so.
Here, we are search for two values between two columns. I found many answer which search for a single value between two columns because thats easy by using between statement in two fields.

When searching for an experience range of a - b , the following query should do the trick:-

SELECT * FROM jobpost WHERE 
(a>=jp_min AND a <= jp_max) OR (b>=jp_min AND b<=jp_max) ;

这是你想要的吗?:-

SELECT * FROM jobpost WHERE (jp_min BETWEEN '1' AND '5') OR (jp_max BETWEEN '1' AND '5') OR (jp_min < '1' AND jp_max > '5');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM