使用 PDO。
SELECT *
FROM time
WHERE
UserId = :uid AND
(
week = :CurrentWeek ||
week = :PreviousWeek1 ||
week = :PreviousWeek2 ||
week = :PreviousWeek3 ||
week = :PreviousWeek4 ||
week = :PreviousWeek5
)
GROUP BY week
ORDER BY week DESC
所以,我试图在这样的表格中打印出过去五周的时间加上当前的时间。
v1 v2 v3 v4 v5
Person 1 40 40 40 40 40
Person 2 39 40 39 40 40
问题是,如果例如。v3 不存在,它将 v4 推到 v3 的位置。我正在寻找试图获取所有周值的东西,如果它们不存在,它会返回该列的默认值。
我想以最好的方式解决这个问题。(我当然可以每周循环并逐个获取值,但它必须是一种更有效的方式)