MySQL条件查询:筛选enable为true且min、max在2-30间的数据行
Alright, let's tackle this filtering problem. Here's how to get the exact result you're looking for:
First, let's lay out your original dataset clearly:
| id | enable | min | max |
|---|---|---|---|
| 1 | true | 4 | 10 |
| 2 | false | 5 | 23 |
| 3 | true | 6 | 45 |
Key Filtering Criteria
We need to apply two layers of checks:
- First, ignore any rows where
enableisfalse—these are excluded entirely. - For rows where
enableistrue, we only keep those where bothminandmaxfall within the range of 2 to 30 (inclusive).
Applying the Filters to Each Row
Let's go through each entry to see which ones qualify:
- Row 1:
enableis true, min=4 (fits 2-30), max=10 (fits 2-30) → kept - Row 2:
enableis false → excluded - Row 3:
enableis true, but max=45 is outside the 2-30 range → excluded
Final Filtered Result
| id | enable | min | max |
|---|---|---|---|
| 1 | true | 4 | 10 |
If you're using a tool like SQL to automate this, here's a sample query that would give you the above result:
SELECT id, enable, min, max FROM your_table WHERE enable = true AND min BETWEEN 2 AND 30 AND max BETWEEN 2 AND 30;
内容的提问来源于stack exchange,提问作者Amin Nazari
相关产品推荐
相关产品推荐

