以下代码旨在为一年中的特定周提取表的记录并汇总数据。除了第0周(2017年12月31日周日是本周的开始),我测试的每个星期的代码运行正常。如果我在phpmyadmin中运行查询,它确实会提供所需的结果。任何人都可以帮助我理解我做错了什么。
try {
$usid=$_SESSION['uid'];
$wk = $_GET['wk'];
$tdy= date("Y-m-d");
$stmt6 = $db->prepare("
SELECT
YEAR(transaction_date) AS YR,
COUNT(
bo_hourly_charges.billing_id_num
) AS EVENTS,
SUM(
CASE
WHEN checkout < '16:31:00'
THEN 1
ELSE 0
END
) AS early,
SUM(
CASE
WHEN checkout > '16:30:00'
THEN 1
ELSE 0
END
) AS late,
bo_school_enrollment.last_first,
WEEK(
bo_hourly_charges.transaction_date
) AS wk,
bo_school_enrollment.student_id,
bo_school_enrollment.family_id,
bo_billing_rates.account,
bo_billing_rates.description,
bo_school_enrollment.faculty_discount
FROM
bo_hourly_charges,
bo_school_enrollment,
bo_billing_rates
WHERE bo_hourly_charges.billing_id_num = bo_school_enrollment.billing_id_num
AND billed_by = 'AfterCare'
AND bo_hourly_charges.billing_rate_id = bo_billing_rates.billing_rate_id
AND WEEK(
bo_hourly_charges.transaction_date
) = :wk
GROUP BY bo_school_enrollment.faculty_discount,
bo_school_enrollment.last_first WITH ROLLUP
");
$stmt6->bindParam(':wk',$wk,PDO::PARAM_STR);
$stmt6->execute();
// set the resulting array to associative
$result6 = $stmt6->setFetchMode(PDO::FETCH_ASSOC);
$count6 = $stmt6->rowCount();
答案 0 :(得分:0)
我发现了一篇回答我问题的文章。 WEEK功能有多种模式,我需要更改模式以获得所需的结果。 https://www.electricmonk.nl/log/2009/04/13/mysql-week-function-weirdness/