gpt4 book ai didi

MySQL 查询日期范围

转载 作者:行者123 更新时间:2023-11-29 01:10:11 24 4
gpt4 key购买 nike

我用谷歌搜索但没有找到任何相关内容。我有一个像这样的 MySQL 表:

+++++++++++++++++++++++++++++++| roomID |    date    | price |+++++++++++++++++++++++++++++++|  1     | 2012-10-10 |   10  ||  1     | 2012-10-11 |   10  ||  1     | 2012-10-12 |   10  ||  1     | 2012-10-13 |   12  ||  2     | 2012-10-10 |   15  ||  2     | 2012-10-11 |   15  ||  2     | 2012-10-12 |   15  ||  2     | 2012-10-13 |   16  ||  2     | 2012-10-14 |   16  ||  2     | 2012-10-15 |   16  |+++++++++++++++++++++++++++++++

我需要根据价格和房间 ID 获取时间段:

++++++++++++++++++++++++++++++++++++++++++++| roomID |    from    |    till    | price |++++++++++++++++++++++++++++++++++++++++++++|    1   | 2012-10-10 | 2012-10-12 |   10  ||    1   | 2012-10-13 | 2012-10-13 |   12  ||    2   | 2012-10-10 | 2012-10-12 |   15  ||    2   | 2012-10-13 | 2012-10-15 |   16  |++++++++++++++++++++++++++++++++++++++++++++

谢谢!

最佳答案

select roomid,
min(date) as from,
max(date) as till,
price
from periods
group by price
order by price

关于MySQL 查询日期范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12873067/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com