MySQL Query Multiple连接每行复制数据? JIRA数据库

时间:2017-02-20 22:23:03

标签: mysql jira

我试图在接下来的30天内为某个组中的每个用户提取工作时间。我不擅长MySQL,所以很多可能是错的。这来自JIRA数据库。

    SELECT DISTINCT cu.display_name AS 'Associate', sum(wl.timeworked/3600) AS '30 Days'
    FROM worklog AS wl, cwd_user AS cu
    INNER JOIN cwd_membership AS cm
        ON cu.directory_id=cm.directory_id
        AND cu.lower_user_name=cm.lower_child_name
        AND cm.membership_type='GROUP_USER'
    INNER JOIN worklog
        ON worklog.AUTHOR = cu.user_name
    WHERE cm.lower_parent_name='atl_servicedesk_it_agents' AND wl.STARTDATE BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 30 DAY)
 ORDER BY cu.last_name;

现在它只显示第一个用户名,其中包含每个人工作时间内所有内容的总和。这显然不是我想要的...如果我从时间工作中删除总和它显示该组中大约一半的用户,但每个用户的工作时间值为16小时,这是不正确的。在接下来的30天内,只有一个用户具有任何值,并且持续16个小时,因此由于某种原因,它会复制此信息。 有什么想法吗?

1 个答案:

答案 0 :(得分:0)

通过取出INNER JOIN来实现它。

SELECT cwd_user.display_name AS 'Associate', sum(worklog.timeworked/3600) AS '30 Days'
FROM worklog, cwd_user,cwd_membership
WHERE worklog.AUTHOR = cwd_user.user_name
and cwd_user.directory_id = cwd_membership.directory_id
and cwd_user.lower_user_name = cwd_membership.lower_child_name
and cwd_membership.membership_type = 'GROUP_USER'
and cwd_membership.lower_parent_name = 'atl_servicedesk_it_agents'
and worklog.STARTDATE BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 60 DAY)
GROUP BY cwd_user. display_name
ORDER BY cwd_user.last_name;