开发者

order by in joined tables

开发者 https://www.devze.com 2023-03-28 11:02 出处:网络
i want to order the second joined table according to price, to exaplain it more clear i will add a screenshot: http://s42.radikal.ru/i098/1108/87/66f19d915bbc.jpg the second table displays the prices:

i want to order the second joined table according to price, to exaplain it more clear i will add a screenshot: http://s42.radikal.ru/i098/1108/87/66f19d915bbc.jpg the second table displays the prices: bayi 1, bayi 2, bayi 3, bayi 4 and liste fiyati, i want to rearrange em in another order starting from liste fiyati and ending on bayi 1. here is my query:

<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>

and the table:

<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#</cf开发者_如何学JAVAoutput></td>
        <td align="center"><cfoutput>#toplam_order_stock#</cfoutput></td>
        <td colspan="12"></td>
    </tr>
</table>

btw, the price i want to order is PRICE PR not the PRICE_STANDART PS, and thank you all for help!


You just need to add both ORDER BY statements:

ORDER BY P.PRODUCT_ID, PS.PRICE DESC

With ColdFusion grouping, make sure that you always sort by what you want to group by first, then you can sort by whatever you need inside the group.


But then change the

ORDER BY PS.PRICE DESC 

to

 ORDER BY PR.PRICE DESC 

Surely?


If I understand what you're asking, you need to include all the cols from the GROUP BY in your ORDER BY statement first, and then add any other columns that you want to order by within those groupings.

But I'm afraid to say yor question isn't terribly clear.

-- Adam

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号