我想在每个月的第一天显示以下代码。 因此对于四月它将拥有自己的'display_count_pending_outer' 一旦5月1日到达,它将显示一个新的'display_count_pending_outer'。 在图像中,我想在每个月的第一天展示它。
<cfquery datasource ="Intranet" name="GetDeptSubmissions">SELECT * FROM CSEReduxResponses</cfquery>
<cfquery dbtype="query" name="GetPending">SELECT * FROM GetDeptSubmissions WHERE status = 1 AND execoffice_status = 0</cfquery>
<cfquery dbtype="query" name="GetApproved">SELECT * FROM GetDeptSubmissions WHERE status = 1 AND execoffice_status = 1</cfquery>
<cfquery dbtype="query" name="GetDenied">SELECT * FROM GetDeptSubmissions WHERE status = 1 AND execoffice_status = 2</cfquery>
<cfoutput>
<div>
<div class="display_count pending_outer">
<div class="display_count_desc pending_inner">Pending</div>
<cfif GetPending.RecordCount gt 0><a href="cse_execoffice_pending.cfm"></cfif>
<span class="display_count_number">#GetPending.RecordCount#</span>
<cfif GetPending.RecordCount gt 0></a></cfif>
</div><!--- /div class="display_count" --->
<div class="display_count approved_outer">
<div class="display_count_desc approved_inner">Approved *</div>
<cfif GetApproved.RecordCount gt 0><a href="cse_execoffice.cfm?approved"></cfif>
<span class="display_count_number">#GetApproved.RecordCount#</span><br>
<cfif GetApproved.RecordCount gt 0></a></cfif>
</div><!--- /div class="display_count" --->
<div class="display_count denied_outer">
<div class="display_count_desc denied_inner">Denied</div>
<cfif GetDenied.RecordCount gt 0><a href="cse_execoffice.cfm?denied"></cfif>
<span class="display_count_number">#GetDenied.RecordCount#</span><br>
<cfif GetDenied.RecordCount gt 0></a></cfif>
</div><!--- /div class="display_count" --->
</div>
</cfoutput>
现在它显示如下
答案 0 :(得分:1)
我认为你正在走很长的路要走。现在,您正在选择该表中的所有内容,然后根据WHERE status=1 and the value of execoffice_status
对其进行过滤。
相反,由于您所追求的是与每个execoffice_status
相关联的记录总数,因此您可以这样编写查询:
SELECT
COUNT(*) AS total_count, execoffice_status
FROM
CSEReduxResponses
WHERE
status = 1
GROUP BY
execoffice_status
哪个应该为表中的execoffice_status
的每个唯一值返回1条记录。如果此查询到目前为止是正确的,那么接下来需要做的是GROUP BY whatever date column you have。
SELECT
CAST(MONTH(date) AS VARCHAR(2)) + '-' + CAST(YEAR(date) AS VARCHAR(4)) AS theDate,
COUNT(*) AS total_count,
execoffice_status
FROM
CSEReduxResponses
WHERE
status = 1
GROUP BY
CAST(MONTH(date) AS VARCHAR(2)) + '-' + CAST(YEAR(date) AS VARCHAR(4))
execoffice_status
您可能需要做的就是在ORDER BY
子句中添加WHERE
子句和日期范围,以进一步过滤结果。此时使用CF输出这些数据应该是轻而易举的事。