-3
我寫了一個sql-server代碼和coldfusion表,有產品和價格,每個產品有5個不同的價格,所有的價格都是正確顯示的,但是他們彼此不同,但是如果產品5的價格相同,則它們被分組爲一個。無論如何希望從代碼和屏幕截圖中清楚一切。sql group如果它們的值相同
這裏是SQL:
SELECT P.PRODUCT_ID,
P.PRODUCT_NAME,
PS.MONEY,
PR.PRICE,
P.BRAND_ID,
PS.PRICE,
GSL.PRODUCT_STOCK,
GSL.PURCHASE_ORDER_STOCK,
GSL.SALEABLE_STOCK,
P.PRODUCT_DETAIL2,
P.BARCOD
FROM PRODUCT P
JOIN PRICE_STANDART PS ON P.PRODUCT_ID = PS.PRODUCT_ID
JOIN PRICE PR ON P.PRODUCT_ID = PR.PRODUCT_ID
JOIN #DSN2_ALIAS#.GET_STOCK_LAST GSL ON P.PRODUCT_ID = GSL.PRODUCT_ID
WHERE PS.PURCHASESALES=1 AND
PS.PRICESTANDART_STATUS=1 AND
P.IS_SALES=1 AND
P.IS_INTERNET=1 AND
P.IS_EXTRANET=1
GROUP BY
P.PRODUCT_ID,
PR.PRICE,
P.PRODUCT_NAME,
PS.MONEY,
P.BRAND_ID,
PS.PRICE,
GSL.PRODUCT_STOCK,
GSL.PURCHASE_ORDER_STOCK,
GSL.SALEABLE_STOCK,
P.PRODUCT_DETAIL2,
P.BARCOD
ORDER BY
P.PRODUCT_ID, PR.PRICE DESC
和表:
<tr class="color-header">
<td width="170"><b>Ürün</b></td>
<td class="header_bold"><b>Açıklama 2</b></td>
<td class="header_bold" width="100"><b>Marka</b></td>
<cfif isdefined('attributes.department_id') and len(attributes.department_id)>
<td class="header_bold" width="35"><b>Depo Stok</b></td>
<cfelse>
<td class="header_bold" width="35"><b>Stok</b></td>
<td class="header_bold" width="50"><b>Satabilen Stok</b></td>
<td class="header_bold" width="35"><b>Yoldaki Stok</b></td>
</cfif>
<cfif (session.ep.admin is 1) or (session.ep.userid is 19)>
<td class="header_bold" width="70">Dön. Sonu B.Maliyet $</td>
</cfif>
<td class="header_bold" width="90">Liste Fiatı</td>
<td class="header_bold" <cfif isdefined('get_company.companycat_id') and len(get_company.companycat_id) and (get_company.companycat_id eq 6)>style="color:yellow;font-size:9pt;background:#000;"</cfif> width="80">Bayi 1</td>
<td class="header_bold" <cfif isdefined('get_company.companycat_id') and len(get_company.companycat_id) and (get_company.companycat_id eq 7)>style="color:yellow;font-size:9pt;background:#000;"</cfif> width="80">Bayi 2 <br /> 12 Ay 0 faiz</td>
<td class="header_bold" <cfif isdefined('get_company.companycat_id') and len(get_company.companycat_id) and (get_company.companycat_id eq 8)>style="color:yellow;font-size:9pt;background:#000;"</cfif> width="80">Bayi 3 <br /> 30-60-90 çek</td>
<td class="header_bold" <cfif isdefined('get_company.companycat_id') and len(get_company.companycat_id) and (get_company.companycat_id eq 9)>style="color:yellow;font-size:9pt;background:#000;"</cfif> width="80">Bayi 4 Tek Çekim Peşin</td>
<cfif (session.ep.admin is 1) or (session.ep.userid is 19)>
<td class="header_bold" width="60">
<cfif isdefined('attributes.yoldaki_stock') and attributes.yoldaki_stock is 1>
Yoldaki
<cfelseif isdefined('attributes.department_id') and len(attributes.department_id)>
Depodaki
<cfelse>
Satabilen
</cfif>Hesapla
</td>
</cfif>
<td class="header_bold" width="25">Para</td>
</tr>
<cfoutput query="get_products" startrow="#attributes.startrow#" maxrows="#attributes.maxrows#" group="product_id">
<cfquery name="get_maliyet" datasource="#dsn3#">SELECT PURCHASE_NET_SYSTEM_MONEY,(PURCHASE_NET_SYSTEM+PURCHASE_EXTRA_COST_SYSTEM) AS DS_MALIYET FROM PRODUCT_COST WHERE PRODUCT_ID=#PRODUCT_ID#</cfquery><cfif len(get_maliyet.ds_maliyet)><cfset toplam_maliyet=get_maliyet.ds_maliyet+toplam_maliyet></cfif>
<tr height="20" onMouseOver="this.className='color-light';" onMouseOut="this.className='color-row';" class="color-row">
<td>
<a href="/index.cfm?fuseaction=product.form_upd_product&pid=#product_id#" style="color:blue;" target="_blank">#left(product_name,25)#</a>
</td>
<td>#left(PRODUCT_DETAIL2,45)#</td>
<td align="center"><cfif len(brand_list)>#get_brands.brand_name\[listfind(brand_list,brand_id,',')\]#</cfif></td>
<cfif isdefined('attributes.department_id') and len(attributes.department_id)>
<td align="center">#product_stock2#</td>
<cfelse>
<td align="center">#PRODUCT_STOCK#</td>
<td align="center">#saleable_stock#</td>
<td align="center">#purchase_order_stock#</td>
</cfif>
<cfif (session.ep.admin is 1) or (session.ep.userid is 19)>
<td align="center"><cfif len(GET_MALIYET.DS_MALIYET)>#tlformat(GET_MALIYET.DS_MALIYET/get_money.rate2,2)#<cfelse>0</cfif></td>
</cfif>
<cfoutput>
<td align="center">#tlformat(price,2)#</td>
</cfoutput>
<cfif (session.ep.admin is 1) or (session.ep.userid is 19)>
<td align="center"><a href="javascript://" onclick="gizle_goster(abr#currentrow#);" style="font-weight:bold;"><cfif isdefined('attributes.yoldaki_stock') and attributes.yoldaki_stock is 1>x #purchase_order_stock#<cfelseif isdefined('attributes.department_id') and len(attributes.department_id)>x #product_stock2#<cfelse>x #saleable_stock#</cfif></a></td>
</cfif>
<td align="center">#MONEY#</td>
</tr>
</cfoutput>
上的截圖U可以快速學習和理解這個問題。當然我編輯了一些代碼並刪除了不必要的部分。大家,謝謝你的幫助! ^^
這就是XML--而不是SQL。請提供SQL!或用XML標記。但這絕對不可讀。 – 2011-12-27 07:57:19
@Jonathan這不是xml!這是sql的人 – user775917 2011-12-27 07:59:57
如果你刪除'group by'子句,會發生什麼? – 2011-12-27 08:21:14