我有一个当前设置,在该设置中,我将数据库中的所有项目与查询类似的atm汇总:
$query01 = "
SELECT COUNT(project_id) as total_week
FROM projects
WHERE WEEK(CURDATE(), 1) between WEEK(project_start, 1) and WEEK(project_delivery, 1)
";
并且每年/每月/每天都进行相同的查询。
我还想输出一个带有向上/向下箭头的比较,每个箭头分别与去年/月/周/日。
我如何实现这样的目标? 预先感谢!
答案 0 :(得分:1)
$thisweek = query("SELECT COUNT(project_id) as total_week
FROM projects
WHERE WEEK(CURDATE(), 1) between WEEK(project_start, 1) and WEEK(project_delivery, 1)");
$lastweek = query("SELECT COUNT(project_id) as total_last_week
FROM projects
WHERE WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK), 1) between WEEK(project_start, 1) and WEEK(project_delivery, 1)");
$comparison = $thisweek - $lastweek;
类似的事情应该可以做到,在这种情况下,我使用的“查询”功能假定仅提取单个计数。