【发布时间】:2015-05-26 19:08:04
【问题描述】:
我有这张表“价格”
id | price_per_week | date_start | date_end
1 | 500 | timestamp | timestamp
1 | 5000 | timestamp | timestamp
2 | 100 | timestamp | timestamp
3 | 300 | timestamp | timestamp
3 | 200 | timestamp | timestamp
3 | 6000 | timestamp | timestamp
3 | 50 | timestamp | timestamp
4 | 600 | timestamp | timestamp
5 | 800 | timestamp | timestamp
5 | 200 | timestamp | timestamp
我想获取最小值和最大值在价格范围之间的所有 id。例如所有最小 price_per_week >= 200 和最大 price_per_week 1000 的 id。
当我运行这个查询时
SELECT id FROM prices WHERE price_per_week BETWEEN 200 AND 1000
它还返回 id 1,3,其 max price_per_week 大于 1000
我认为我应该以某种方式使用子查询,但我仍在学习......
【问题讨论】:
标签: mysql