计算每个用户的总记录 [英] count total records for each user
问题描述
我有这段代码可以拉动所有带有打开请求的用户.我需要显示每个分配的买方的总计.
I have this code that pulls all users with open requests. I need to show a total for each assigned buyer.
<CFQUERY NAME="allbuyers" DATASOURCE="procuresource3">
SELECT *
FROM allorders3
WHERE open = 'y'
order by assignedbuyer
</cfquery>
<cfoutput query="allbuyers">
#assignedbuyer# #prn#
</cfoutput>
<cfoutput>
Total: #allbuyers.RecordCount#
</cfoutput>
输出是所有记录.我需要为每个用户总计.如下所示:
The output is all records. I need a total for each user. Something like this below:
Christine - 301366
Christine - 300729
Christine - 300731
Christine - 300732
Total: 4
<br>
Connie - 301524
Connie - 301516
Connie - 301510
Connie - 301509
Connie - 301460
Connie - 301362
Total: 6
<br>
Dannette - 301478
Dannette - 301458
Dannette - 301340
Total: 3
先谢谢您. 卡洛斯·L
Thank you in advance. CarlosL
推荐答案
有多种方法可以通过查询调整来获取计数并通过唯一键建立结构计数.
There are multiple ways to accomplish this with query adjustments to get counts and building up struct counts by unique key.
当前最直接的方法是根据当前已分配的买方与先前的已分配买方是否相同来建立计数.当查询group
列更改时,CF提供了一种内置方法来使代码循环运行.
The most straight forward with where you are currently is to build up a count based on whether the current assignedbuyer is the same as the previous assignedbuyer. CF provides a built-in way to have code run in a loop when a query group
column changes.
<cfset q = queryNew("") />
<cfset queryAddColumn(q, "name", "varchar", ['Dan','Dan', 'Bob', 'Bob', 'Bob', 'Chris']) />
<cfoutput query="q" group="name">
<cfset count = 0 />
<p>
<cfoutput>
#name#<br />
<cfset count += 1 />
</cfoutput>
Total: #count#
</p>
</cfoutput>
输出
<p>
Dan<br>
Dan<br>
Total: 2
</p>
<p>
Bob<br>
Bob<br>
Bob<br>
Total: 3
</p>
<p>
Chris<br>
Total: 1
</p>
这篇关于计算每个用户的总记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!