1

我有以下表格:

http://www.gulllakeschools.net/mysqltables.pdf

在此处输入图像描述

我需要以这种格式提取数据:学生姓氏、学生名字、日期事件、日期事件(学生登录的每一天都会有一个日期事件)

组件 com_users 是我需要从组件列中提取的组件。

我是主要的 mysql 菜鸟,无法弄清楚如何一次完成所有操作。我有这些单独工作的选择语句:

SELECT civicrm_contact.last_name, civicrm_contact.first_name, civicrm_uf_match.uf_id
FROM civicrm_contact, civicrm_uf_match
WHERE civicrm_contact.id = civicrm_uf_match.contact_id

SELECT user_id, component, group_concat( date_event )
FROM jos_content_statistics
WHERE component = "com_users"
GROUP BY user_id

但我一辈子都不能让他们加入。我试过加入、加入、完全加入、联合,都产生错误。我在 where 语句之前和之后都尝试过加入。联合产生整理错误。我没有尝试过内部连接,因为我无法弄清楚那个。

4

3 回答 3

1
SELECT C.last_name, C.first_name, S.date_event
FROM civicrm_contact as C
INNER JOIN civicrm_uf_match as M on M.contact_id = C.id 
INNER JOIN jos_content_statistics as S on M.uf_id = S.user_id
于 2012-10-09T11:04:47.227 回答
0
SELECT 
  civicrm_contact.last_name, 
  civicrm_contact.first_name, 
  civicrm_uf_match.uf_id,
  (select group_concat(jos_content_statistics.date_event) 
   from jos_content_statistics 
   where user_id = civicrm_uf_match.uf_id 
     and civicrm_uf_match.contact_id = civicrm_contact.id 
     and component = "com_users" 
   GROUP BY user_id) as date_events
FROM civicrm_contact join civicrm_uf_match
on civicrm_contact.id = civicrm_uf_match.contact_id
where civicrm_contact.contact_sub_type='student' 
于 2012-10-09T10:57:09.100 回答
0

试试这个:

SELECT cc.last_name, cc.first_name, cm.uf_id, jc.component, jc.dateevent 
FROM civicrm_contact cc
INNER JOIN civicrm_uf_match cm ON cc.civicrm_contact.id = cm.contact_id
INNER JOIN
(
    SELECT user_id, component, group_concat( date_event ) dateevent
    FROM jos_content_statistics
    WHERE component = "com_users"
    GROUP BY user_id, component
) jc ON cm.uf_id = jc.user_id
于 2012-10-09T10:57:22.577 回答