You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hi All,
Brand new to both Jira and SQL so please bear with me!
I'm using SQL to select the time worked on certain activities by employees. The base query works fine (validated via other means). However, when I add a simple 'group by' to the query, only a fraction of the data is returned compared to the original.
Base query used:
select
wl.author,
truncate(wl.timeworked/3600, 2) as 'Time (Hrs)'
from
jiraissue ji
join customfieldvalue cfv on cfv.ISSUE = ji.ID
join customfield cf on cf.ID = cfv.CUSTOMFIELD
join customfieldoption cfo on cfo.CUSTOMFIELD = cf.ID and cfo.ID = cfv.STRINGVALUE join worklog wl on wl.issueid = ji.ID
join project p on p.ID = ji.PROJECT
where
cf.cfname = 'Bill work to Customer' and
cfo.customvalue <> 'Internal' and
(wl.startdate >= '2023-07-01 07:00:00') and (wl.startdate < '2023-10-01 07:00:00')
This returns 4630 rows, equating to 93 unique users and a total time of 6436.78 hrs.
Modified query (just adding group by):
select
wl.author,
truncate(wl.timeworked/3600, 2) as 'Time (Hrs)'
from
jiraissue ji
join customfieldvalue cfv on cfv.ISSUE = ji.ID
join customfield cf on cf.ID = cfv.CUSTOMFIELD
join customfieldoption cfo on cfo.CUSTOMFIELD = cf.ID and cfo.ID = cfv.STRINGVALUE join worklog wl on wl.issueid = ji.ID
join project p on p.ID = ji.PROJECT
where
cf.cfname = 'Bill work to Customer' and
cfo.customvalue <> 'Internal' and
(wl.startdate >= '2023-07-01 07:00:00') and (wl.startdate < '2023-10-01 07:00:00')
group by wl.author
This returns 93 rows (as expected) but only a total of 430.04 hrs.
Is anyone able to explain to me why the addition of a 'group by' would cause this effect?
Thanks in advance for helping a noob...!
Hi there,
Think you can replace truncate(wl.timeworked/3600, 2) as 'Time (Hrs)' with round(sum((wl.timeworked/3600), 2)) as 'Time (Hrs)'.
Then with the group by wl.author
See if that solves you problem
That worked perfectly - thanks KorstenB.
Now to spend some time learning why that worked, but for now I'm underway. Thanks again for taking the time to review & respond!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.