Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
with t as
                    ( SELECT cwd_group_par.id as project
                    , cwd_group_par.group_name as project_name
                    , case
                    when TO_CHAR(chgroup.created,'YYYY-MM-DD') >= '2015-06-24' AND TO_CHAR(chgroup.created,'YYYY-MM-DD') <= '2015-06-30' then 'LASTWEEK_COUNT'
                    when TO_CHAR(chgroup.created,'YYYY-MM-DD') >= '2015-06-01' AND TO_CHAR(chgroup.created,'YYYY-MM-DD') <= '2015-06-30' then 'LASTMONTH_COUNT'
                    when TO_CHAR(chgroup.created,'YYYY-MM-DD') >= '2015-07-01'AND TO_CHAR(chgroup.created,'YYYY-MM-DD') <= '2015-07-07' then 'CURRENTWEEK_COUNT'
                     end as tm
                    , count(distinct i.id) cnt
                    from jira.jiraissue i
                    join jira.cwd_membership cwd_mem on i.assignee =  cwd_mem.lower_child_name
                    join jira.cwd_group cwd_group_par on cwd_group_par.lower_group_name = cwd_mem.lower_parent_name
                    join jira.issuestatus on i.issuestatus = jira.issuestatus.id
                    JOIN jira.PROJECT ON i.PROJECT = jira.PROJECT.ID 
                    join jira.changegroup chgroup on i.id = chgroup.issueid
                    join jira.changeitem chitem on chgroup.id = chitem.groupid 
                    where cwd_group_par.id in("+str(projectids)+"
                    )
                    and issuestatus in (6 
                         )
                    AND jira.PROJECT.PKEY = 'ISD'
                    AND chitem.field = 'status' and to_char(chitem.newstring) in ('Closed')
                    
                    group by cwd_group_par.id, cwd_group_par.group_name
                    , case when TO_CHAR(chgroup.created,'YYYY-MM-DD') >= '2015-06-24' AND TO_CHAR(chgroup.created,'YYYY-MM-DD') <= '2015-06-30' then 'LASTWEEK_COUNT'
                    when TO_CHAR(chgroup.created,'YYYY-MM-DD') >= '2015-06-01' AND TO_CHAR(chgroup.created,'YYYY-MM-DD') <= '2015-06-30' then 'LASTMONTH_COUNT'
                    when TO_CHAR(chgroup.created,'YYYY-MM-DD') >= '2015-07-01' AND TO_CHAR(chgroup.created,'YYYY-MM-DD') <= '2015-07-07' then 'CURRENTWEEK_COUNT'
                    end 
                    )
                    select * from t
                    pivot
                    ( sum(cnt) as wk
                    for tm in ('LASTMONTH_COUNT','LASTWEEK_COUNT','CURRENTWEEK_COUNT')
                    )
                    order by 1;
Posted
Updated 9-Jul-15 1:34am
v3
Comments
Advay Pandya 9-Jul-15 2:16am    
Please re-format your query. It's really not readable properly.
rohith kallingal 9-Jul-15 7:36am    
now i am updated the query. is it ok?
if you have dbvisualizer tool you can run the query there.
Jörgen Andersson 12-Jul-15 18:52pm    
I can't immediately see what's wrong, but I have a few notes.
You should probably change
TO_CHAR(chgroup.created,'YYYY-MM-DD') >= '2015-06-24' AND TO_CHAR(chgroup.created,'YYYY-MM-DD') <= '2015-06-30'
to
chgroup.created BETWEEN TO_DATE('2015-06-24','YYYY-MM-DD') AND TO_DATE('2015-06-30','YYYY-MM-DD')
as it allows you to use an eventual index on chgroup.created.

And a last question, in what way is the count wrong?

I'm also wondering if CURRENTWEEK_COUNT equals the last seven days or if it represents a work week, same goes for LASTWEEK_COUNT and LASTMONTH_COUNT

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900