在连接表中排序

时间:2011-08-17 08:47:25

标签: sql join coldfusion sql-order-by

我想根据价格订购第二张加入的桌子,更加清楚地说明我会添加截图:http://s42.radikal.ru/i098/1108/87/66f19d915bbc.jpg第二张桌子显示价格:bayi 1,bayi 2,bayi 3,bayi 4 and听fiyati,我想以另外的顺序重新排列em,从liste fiyati开始到结尾于bayi 1.这是我的查询:

<cfquery name="get_products" datasource="#dsn3#">
    SELECT P.PRODUCT_ID,P.PRODUCT_NAME,PS.MONEY,PR.PRICE,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK
    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 P.IS_SALES=1 AND P.IS_INTERNET=1 AND PS.PURCHASESALES=1 AND PS.PRICESTANDART_STATUS=1
    AND PR.STARTDATE <= #now()# AND (PR.FINISHDATE >= #now()# OR PR.FINISHDATE IS NULL)
    GROUP BY P.PRODUCT_ID,PR.PRICE,P.PRODUCT_NAME,PS.MONEY,P.BRAND_ID,PS.PRICE,GSL.PRODUCT_STOCK,GSL.PURCHASE_ORDER_STOCK
    ORDER BY PS.PRICE DESC
</cfquery>

和表格:

<table cellpadding="3" cellspacing="1" class="color-border" width="100%">
    <tr class="color-header">
        <td><b>Ürün</b></td>
        <td class="header_bold" width="80"><b>Marka</b></td>
        <td class="header_bold" width="35"><b>Stok</b></td>
        <td class="header_bold" width="35"><b>Yoldaki Stok</b></td>
        <td class="header_bold" width="80">Bayı 4</td>
        <td class="header_bold" width="80">Bayı 3</td>
        <td class="header_bold" width="80">Bayı 2</td>
        <td class="header_bold" width="80">Bayı 1</td>
        <td class="header_bold" width="80">Liste fiyatı</td>
        <td class="header_bold" width="25">Para</td>
    </tr>
    <cfoutput query="get_products" startrow="#attributes.startrow#" maxrows="#attributes.maxrows#" group="product_id">
        <tr height="20" onMouseOver="this.className='color-light';" onMouseOut="this.className='color-row';" class="color-row"> 
            <td>#product_name#</td>
            <td align="center"><cfif len(brand_list)>#get_brands.brand_name[listfind(brand_list,brand_id,',')]#</cfif></td>
            <td align="center">#PRODUCT_STOCK#</td>
            <td align="center">#purchase_order_stock#</td>
            <cfoutput><td align="center">#tlformat(price,2)#</td></cfoutput>
            <td align="center">#MONEY#</td>
        </tr>
    <cfset toplam_stock = toplam_stock+product_stock>
    <cfset toplam_order_stock = toplam_order_stock+purchase_order_stock>
    </cfoutput>
    <tr class="color-header">
        <td colspan="2"></td>
        <td align="center"><cfoutput>#toplam_stock#</cfoutput></td>
        <td align="center"><cfoutput>#toplam_order_stock#</cfoutput></td>
        <td colspan="12"></td>
    </tr>
</table>
顺便说一句,我想订购的价格是PRICE PR而不是PRICE_STANDART PS,谢谢大家的帮助!

3 个答案:

答案 0 :(得分:4)

您只需要添加两个ORDER BY语句:

ORDER BY P.PRODUCT_ID, PS.PRICE DESC

使用ColdFusion分组,确保您总是按照您想要分组的内容排序,然后您可以按照组内的任何需要进行排序。

答案 1 :(得分:0)

然后改变

ORDER BY PS.PRICE DESC 

 ORDER BY PR.PRICE DESC 

当然?

答案 2 :(得分:0)

如果我理解您的要求,则需要在ORDER BY语句中包含GROUP BY中的所有cols,然后添加您要在其中排序的任何其他列那些分组。

但我不敢说你的问题不是很清楚。

- 亚当