2013-02-18 37 views
0

我有這樣的MySQL查詢集團通過限2臺

 select * from {$this->table} sc 
     join db_sc_profile scp 
     on scp.subcategory_id = sc.subcategory_id 
     join db_profile p 
     on p.profile_id = scp.profile_id 
     where sc.subcategory_id in (" . implode(',', $subcategories) . ") 
     and p.profile_id in (" .implode(',', $profiles) . 
     group by p.profile limit #### 

此查詢不與該行group by p.profile limit ####工作。所以 我想分組p.profile但限制爲12/count(profiles)

我可以那樣做嗎?請任何幫助。

注:我使用的是笨2

+0

1:你嘗試了嗎? 2:在倒數第二行有一個語法錯誤(在連接implode之後不要重新打開雙引號)。 – 2013-02-18 17:55:38

+0

給我們一個輸入樣本和預期輸出。 – Achrome 2013-02-18 17:59:29

+0

是的,我知道這是工作,我修改它只是爲了向你展示如何添加組和限制。我可以解釋:我想要例如6個子類別的個人資料 – 2013-02-18 18:00:12

回答

0

輸入例

[subcategories] = Array 
(
[0] => 101 
[1] => 102 
[2] => 103 

) 

[profiles] => Array 
    (
     [0] => 5 
     [1] => 6 
    ) 

他們在數據庫中的兩個表的第三個錶鏈接

profile = [profile_id, profile_name] 

subcategory = [sc_id, sc_name,...] 

profile_subcategory = [profile_id, sc_id]