我正在尝试进行查询以运行报告。我试图让它搜索一系列日期并检查用户做了多少工作。 Closed_by
是显示用户数量的字段,表示他们已完成工作,op_id
表示他们已提交作品。有没有办法可以通过细分来报告每个人的所作所为?
<cftry>
<cfquery name="received" datasource="dns">
Select *
FROM dbo.Dealer_Track_Work
WHERE Date_Received between <cfqueryparam value="10/13/2015" />
AND <cfqueryparam value="10/26/2015" />
WHERE Closed_by <cfqueryparam value="192" />
AND op_id <cfqueryparam value="192" />
</cfquery>
<cfdump var="#received#" label="received">
<!---<cfquery name="users" dbtype="query">
Select *
FROM received
WHERE Closed_by <cfqueryparam value="192" />
AND op_id <cfqueryparam value="192" />
</cfquery>
<cfdump var="#users#" label="users">--->
<cfcatch type="any">
<cfset result.error = CFCATCH.message >
<cfset result.detail = CFCATCH.detail >
</cfcatch>
</cftry>
答案 0 :(得分:3)
您可以抛弃where子句并将其替换为group by子句。 您还应该列出列而不是使用select *
Select op_id
,count(op_id) as itemsOpened
,count(closed_by) as itemsClosed
FROM dbo.Dealer_Track_Work
WHERE Date_Received between <cfqueryparam value="10/13/2015" />
AND <cfqueryparam value="10/26/2015" />
AND op_id IN (<cfqueryparam value="192,229,123" list="true">)
GROUP BY op_id
ORDER BY op_id ASC
您的查询可能还需要某种聚合,以便您知道您的工作定义。
修改:修改以获取打开和关闭的项目,添加过滤