SQLite Count Summary Query -


i'm trying query summarize each employees work week. example, john doe did total of 12 tickets week, 4 of break/fixes, , 4 enhancement, , 4 uncategorized.

this have far:

select (users.first_name || ' ' || users.last_name) name,   count(tickets.id) 'number of tickets closed',   count(tickets.category = 'maintenance') 'maintenance tickets',   count(tickets.category = 'after hours') 'after hours tickets',   count(tickets.category = 'break fix') 'break fix tickets',   count(tickets.category = 'enhancement') 'enhancement tickets',   count(tickets.category = '') 'non categorized tickets' tickets, users on tickets.assigned_to=users.id (tickets.status = 'closed') ,   (tickets.closed_at >= '2011-07-16 00:00:00') ,   (tickets.closed_at <= '2011-07-22 23:59:59') group name; 

here sample result:

john doe1 10 10 10 10 10 10

john doe2 2 2 2 2 2 2

john doe3 25 24 24 24 24 24

john doe4 2 2 2 2 2 2

john doe5 12 10 10 10 10 10

john doe6 7 7 7 7 7 7

this query doesn't quite work expected of columns have same total (the total number of tickets closed, following columns seems contain categorized ones.) help?

edit

just wanted post functional code:

select (users.first_name || ' ' || users.last_name) name,   count(tickets.id) 'number of tickets closed',   count(case tickets.category when 'maintenance' 1 else null end) 'maintenance tickets',   count(case tickets.category when 'after hours' 1 else null end) 'after hours tickets',   count(case tickets.category when 'break fix' 1 else null end) 'break fix tickets',   count(case tickets.category when 'enhancement' 1 else null end) 'enhancement tickets',   count(case tickets.category when '' 1 else null end) 'non categorized tickets' tickets, users on tickets.assigned_to=users.id (tickets.status = 'closed') ,   (tickets.closed_at >= '2011-07-16') ,   (tickets.closed_at <= '2011-07-22') group name; 

you may want use count this

...     count(case tickets.category when 'maintenance' 1 else null end),     count(case tickets.category when 'after hours' 1 else null end), ... 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -