在codeigniter中添加两个查询的计数?

时间:2014-04-25 05:27:42

标签: php mysql sql codeigniter

我有4张桌子 我查询: -  1.活动:有活动ID  2. activity_specialties:有活动ID和专业  用户:专业  4.列出项目

II查询:

  1. 活动:有活动ID
  2. icd10_assignments:activity_assignment_id
  3. 我必须从I查询和II查询中找到计数 并添加这些计数结果以查找总结果  我的列是活动ID和总计数 我的两个疑问是 1)

    SELECT `activity`.`activity_id`, count(distinct users.id) as user_id
    FROM (`activity`)
    JOIN `activity_specialties` ON `activity`.`activity_id` = `activity_specialties`.`activity_id`
    LEFT JOIN `users` ON `users`.`specialty`= `activity_specialties`.`specialties_id`
    WHERE `activity_category` =  'Online CME Activities'
    GROUP BY `activity`.`activity_id`
    

    2)

    SELECT `activity`.`activity_id`, count(icd10_assignments.id) as assign_id
    FROM (`activity`)
    JOIN `icd10_assignments` 
    ON `activity`.`activity_id`= `icd10_assignments`.`activity_assignment_id`
    WHERE `activity_category` =  'Online CME Activities'
    GROUP BY `activity`.`activity_id`
    

0 个答案:

没有答案