說我有一個表稱爲「用戶」,它有40行的記錄,每行有字段:MySQL查詢排序和訂購
id, firstname, group_id, login_count, stay_on_page_count
組具有
administrator (1), manager (2), employee (3)
是有可能創建一個查詢,將排序和排序行這種方式
group _id stay_on_page_count login_count
========= ================== ===========
1 100mins 100
1 90mins 90
2 100mins 100
3 100mins 100
1 80mins 80
1 70mins 70
2 90mins 90
3 90mins 90
1 60mins 60
1 50mins 50
2 80mins 80
3 80mins 80
1 40mins 40
1 30mins 30
2 70mins 70
3 70mins 70
基本上我想創建一個4x4網格視圖使用查詢結果LT。僞代碼可能
SELECT all FROM user table and to group the result in to cluster of 4,
while each 4 should have ORDER BY group_id ASC as first priority (1,1,2,3)
AND stay_on_page_count ORDER BY DESC as second priority,
AND login_count ORDER BY DESC as last or third priority
我不知道的僞代碼解釋就夠了,但是這是我可以:)
,如果它能夠想出的唯一的事情,然後將它犧牲性能? 有沒有更好的方法來實現這一目標?
我使用MySQL和PHP(CakePHP的2.x的)
感謝
讀取您的示例輸出,我找不出排序條件。你能解釋一下嗎? (僞代碼是受歡迎的) – RandomSeed
你可以在PHP代碼本身做到這一點。據我所知,沒有簡單的解決方案來按列分類結果。 – skparwal
@YaK我已經添加了僞代碼,希望它解釋:) – littlechad