duan201444 2017-04-03 16:58
浏览 33

在查询具有MIN和MAX列的mysql时,如何获得正确的数字列表?

So I have a table in mysql that has on it columns for a Minimum number and a maximum number.

| ID | MinNumber | MaxNumber |
| 1  | 2         | 4         |
| 2  | 3         | 7         |
| 3  | 10        | 12        |

I want to get a list of numbers that is included in all ranges.

So the list should look like: 2, 3, 4, 5, 6, 7, 10, 11, 12 Notice that 8 and 9 are missing because they are not within a range on the table.

Is there an easy way to get this range?

If it helps, I am trying to do this using PHP.

EDIT: This needs to run optimally. The real table has over 200,000 rows in it and the ranges can be hundreds apart. Any way to cut down on the processing time for this would help a lot!

  • 写回答

2条回答 默认 最新

  • douan3414 2017-04-03 17:04
    关注

    I would query the database for all rows. Then have a while loop run untill there are no rows. Inside that while loop run a simple for statement like so: for ($i = MinNumber; $i < MaxNumber; $i++) {

    Then just simply push to an array and print out the array after the while loop.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器