我有一個LIST(查詢輸出),它具有來自表「Account」的不同ID。 使用該LIST我正在LOOPING SELECT查詢並基本上提取一些COUNT。 我無法單獨獲取COUNT值。無法使用列表獲取所需的輸出,<cfloop>和<cfquery>
表「帳戶」具有字段 1)contract_ID,
2)vAccountID(主鍵)和 3)STATUS_ID(值=」」,V,C)。
我做下面的查詢
<cfquery name="qryGetid" datasource="#datasource#">
SELECT DISTINCT(contract_ID)
FROM Account
ORDER BY contract_ID DESC
</cfquery>
<!--- account details for each --->
<cfset Z =#ValueList(qryGetid.ID)# >
<cfloop list="#Z#" index="Y" >
<cfquery name="qryGetNiceAccounts" datasource="#dataSource#">
SELECT
DISTINCT(a.contract_ID)
,(SELECT count(vAccountID) FROM Account
WHERE c _ID IN (<cfqueryparam value="#x#" list="yes" cfsqltype="cf_sql_integer" separator=",">)
AND Status_id = 'V') AS Valid_AcntV
,(SELECT count(vAccountID) FROM Account
WHERE c _ID IN (<cfqueryparam value="#x#" list="yes" cfsqltype="cf_sql_integer" separator=",">)
AND Status_id = 'C') AS Valid_AcntC
FROM Account a
WHERE
a.contract_ID IN (<cfqueryparam value="#x#" list="yes" cfsqltype="cf_sql_integer" separator="," >)
ORDER BY contract_ID DESC
</cfquery>
查詢=「qryGetNiceAccounts」在列表中的「Valid_AcntCount」甚至是不同的「C_ID」只返回一個值。
例如,如果「客戶」表中有基本上我有麻煩了各自的ID計數值
contract_ID count(vID)/ v_Accoun t=’v’ count(vID)/ v_Accoun t=’c’
123 10 220
124 05 110
123 01 0
contract_ID count(vID)/ v_Accoun t=’v’ count(vID)/ v_Accoun t=’c’
123 10 220
124 10 220
123 10 220
。
附註: - 當我做了轉儲輸入「contract_ID」被顯示爲123,123 123,而不是123124125
如果你做一個,你看到了什麼? –
charliegriefer
2010-12-02 16:24:49
附註:當你只能循環查詢本身時,你爲什麼要從查詢中遍歷一個`ValueList()`? – Tomalak 2010-12-02 16:37:07