mysql - [My]SQL Query Syntax which requires foreach processing -
i have sql query task can ok in c# or linqpad prefer in sql standard reporting tools can it.
end db bugzilla under mysql
the problem need loop through bug_activity looking particular changes consider parent record "valid", how ? e.g. pseudo logic
if bug_status went in backlog bug_status went assigned , happened 2016-03-01 206-03-31 consider valid record
i unsure how web examples show declare , loops how loop fits "select, from, where" code.
set @bugid = 64252; select bugs_activity.bug_id, -- profiles.realname, -- profiles.login_name, bugs_activity.bug_when, fielddefs.name, bugs_activity.added -- bugs_activity.removed bugs_activity, profiles, fielddefs -- real world 'where xx' have more logic , result in number of bugzilla records -- each bugzilla record has own 'bugs_activity' -- logic needs @ each buzilla records historyto filter results -- want end filtered record set , total number of records bug_id = @bugid , bugs_activity.who = profiles.userid , bugs_activity.fieldid = fielddefs.id
example of bug_activity
bug_id bug_when name added 64252 26/01/2016 6:51:30 status_whiteboard id:103138574 64252 26/01/2016 6:52:10 cc xxx@abc.com 64252 28/01/2016 9:49:10 bug_status in backlog 64252 28/01/2016 9:49:10 cf_escalation_notes effort: 2 reproduced support 64252 28/01/2016 9:49:10 assigned_to def@abc.com 64252 2/05/2016 4:33:05 pm bug_status assigned
select bug_id, sum(case when bug_status='in backlog' 1 else 0 end) backlogcount, sum(case when bug_status='assigned' 1 else 0 end) assignedcount bugs_activity action_date between '2016-03-01' , '206-03-31' group bug_id having backlogcount>0 , assignedcount>0
the select returns bug_ids in 'in backlog' , in 'assigned' statuses during period. can use query above in section instead of bugs_activity
update:
add in select section
max(case when bug_status='in backlog' action_date else null end) backlogdate, max(case when bug_status='assigned' action_date else null end) assigneddate
and in having section and backlogdate<assigneddate
Comments
Post a Comment