按2个表限制分组

时间:2013-02-18 17:51:16

标签: mysql

我有这个MYSQL查询

        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)

我能这样做吗?请任何帮助。

注意:我正在使用Codeigniter 2

1 个答案:

答案 0 :(得分: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]
相关问题