作爲I was advised by a good man and programmer我應該簡化我的表。到目前爲止,我已經創建了一個新表格(x-month,y-cities,value-Nettotal),但我仍不明白爲什麼它不能將城市的值(淨值)分組。這個月沒關係,但值只是從左到右從左到右,沒有任何遺漏。無論如何,我希望你會明白一切從來源:通過城市
這裏查詢:
<cfquery name="GET_SALES_TOTAL" datasource="#dsn#">
SELECT
SUM(COALESCE(nettotal,0)) nettotal,
SC.CITY_ID,
DATEPART(MM,INVOICE_DATE) AY,
C.FULLNAME,
SC.CITY_NAME
FROM
#DSN2_ALIAS#.INVOICE I,
SETUP_CITY SC,
COMPANY C
WHERE
C.COMPANY_ID=I.COMPANY_ID
AND SC.CITY_ID=C.CITY
AND PURCHASE_SALES=1
GROUP BY
DATEPART(MM,INVOICE_DATE),
SC.CITY_ID,
C.FULLNAME,
SC.CITY_NAME
ORDER BY
AY,CITY_ID
</cfquery>
<cfquery name="GET_SALES_GRAND_TOTAL" datasource="#dsn#">
SELECT SUM(NETTOTAL) NETTOTAL,SC.CITY_ID,SC.CITY_NAME
FROM #DSN2_ALIAS#.INVOICE I,SETUP_CITY SC,COMPANY C
WHERE C.COMPANY_ID=I.COMPANY_ID AND SC.CITY_ID=C.CITY AND PURCHASE_SALES=1
GROUP BY SC.CITY_ID, SC.CITY_NAME
ORDER BY CITY_ID,CITY_NAME
</cfquery>
,這裏是表本身:
<table cellpadding="3" cellspacing="1" class="color-border">
<tr class="color-header">
<td></td>
<cfoutput query="GET_SALES_GRAND_TOTAL" group="city_id">
<td>#city_name#</td>
</cfoutput>
</tr>
<cfoutput query="GET_SALES_TOTAL" group="AY"><!--- months first --->
<tr class="color-row"><!--- month-specific stuff goes here --->
<td>#ay#</td>
<cfoutput group="city_id"><!--- city-specific stuff --->
<td>#tlformat(nettotal,2)#<!--- format NETTOTAL however you want here ---></td>
</cfoutput>
</tr>
</cfoutput>
<tr class="color-header">
<td>City Overal</td>
<cfoutput query="GET_SALES_GRAND_TOTAL" group="city_id">
<td>#tlformat(nettotal,2)#<!--- format NETTOTAL here ---></td>
</cfoutput>
</tr>
</table>
下面是截圖,以使其更清晰:
其他的東西除了分組城市完美!
截圖真正幫助:這是要容易得多當我們能夠看到你想要做什麼以及你的結果是什麼時,回答問題。 –
@Dave,希望現在或多或少清楚))btw截圖1,2,3,4,5,6,7是數字:)但沒有命名em但 – user775917