如何使用foreach loop MYSQL month at 在 PHP 中添加月份到 +1 个月



我编码MYSQL(参考代码到 https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all)到:

SELECT * FROM [Orders]
WHERE OrderDate LIKE '1996-01-%'

显示结果仅显示 1996-01-01 到 1996-01-31 的订单日期。

我希望结果在 PHP 中将 MYSQL 月循环到 +1 个月。

示例到实际结果:

显示订单日期 1996-02-01 至 1996-02-28
显示订单日期 1996-03-01 至 1996-03-31
...
显示订单日期 年-月-日到 年-月-日

之后你可以这样使用,你可以在编程结束时合并数据

select *,max(case when month(OrderDate)=1 then OrderDate end) Jan,
max(case when month(OrderDate)=2 then OrderDate end) Feb,
max(case when month(OrderDate)=3 then OrderDate end) Mar,
max(case when month(OrderDate)=4 then OrderDate end) Apr
from Orders
group by month(Orders.OrderDate)`

最新更新