我在下面有這個巨大的醜陋查詢,我想在目錄視圖中對它進行排序。思考類似http://wow.dev:3000/catalog_items?&order=deals。百萬提前感謝您的任何意見或答案。使用URL參數進行sql查詢排序
select 100 - round((current_price/item.estimated_price)*100) as percent, item.cached_thumbnail_url, item.item_id, it.name,
ci.current_price, ci.close_date
from item
join catalog_item ci on ci.item_id = item.item_id
join item_translations as it on (it.item_id = item.item_id)
where (100 - round((current_price/item.estimated_price)*100)) > 49 and
item.estimated_price > 0 and ci.current_price > 0 and ci.close_date > now() and item.active = 1 and ci.active = 1 and
(current_price/estimated_price) < 1
order by (ci.close_date < DATE_ADD(now(), INTERVAL 17 hour)) and (item.estimated_price - current_price) desc
limit 12
是您使用此查詢返回的信息構建目錄頁面?或者是其他東西? – octern 2012-07-26 05:46:37