mysql - SQL Query for ID to filter against date -
basically have query returns data tracking tool. query is:
select `bh`.`bug_id`, `p`.`name` `project`, `p2`.`name` `portfolio`, `u`.`username` `user`,from_unixtime( `bh`.`date_modified` ) `modify_ts`, case `b`.`category_id` when '0' 'no category' when '1' 'all projects general' when '185' '1. req - requirements' when '186' '2. des - design' when '180' '3. dev - development phase testing' when '181' '4. qat - quality assurance testing' when '182' '5. bat -experian business accecptance testing' when '183' '6. uat - external client user testing' when '184' '7. war - warranty period' when '223' '[mort phase 3] 8. defect density' else `b`.`category_id` end `category`, case `b`.`severity` when '40' 'cosmetic' when '50' 'minor' when '60' 'major' when '70' 'critical' end `severity`, case `b`.`priority` when '20' 'low' when '30' 'medium' when '40' 'high' when '50' 'very high' end `priority`, case `b`.`resolution` when '10' 'open' when '20' 'passed testing' when '60' 'duplicate' when '70' 'change request' when '80' 'deferred' when '90' 'rejected' end `resolution`, case `b`.`status` when '10' 'new' when '20' 'clarification' when '40' 'fixed' when '50' 'open' when '80' 'ready test' when '90' 'closed' end `status` `bugtracker`.`mantis_bug_history_table` `bh` left join `bugtracker`.`mantis_bug_table` `b` on `bh`.`bug_id` = `b`.`id` left join `bugtracker`.`mantis_user_table` `u` on `bh`.`user_id` = `u`.`id` left join `bugtracker`.`mantis_project_table` `p` on `b`.`project_id` = `p`.`id` left join `bugtracker`.`mantis_project_hierarchy_table` `ph` on `b`.`project_id` = `ph`.`child_id` left join `bugtracker`.`mantis_project_table` `p2` on `ph`.`parent_id` = `p2`.`id`
and example snippet of output columns removed is:
> 19213 triggers uat 14/08/2014 11:00 major high open new 19213 triggers uat 14/08/2014 11:00 major high open new 19213 triggers uat 14/08/2014 11:00 major high open new 19213 triggers uat 04/08/2014 15:30 major high open new 19213 triggers uat 04/08/2014 15:30 major high open new 19394 triggers uat 15/08/2014 14:24 major high open new 19394 triggers uat 15/08/2014 14:24 major high open new 19394 triggers uat 14/08/2014 10:56 major high open new 19394 triggers uat 14/08/2014 10:56 major high open new 19432 triggers uat 15/08/2014 14:32 major high open new 19432 triggers uat 15/08/2014 14:32 major high open new
what want within query each id (far left column - bh
.bug_id
), return 1 latest date (3rd column - bh
.`date_modified). can throw distinct on top of one's return same if need be.
is there way me filter query essentially?
implemted code added query above :
from `bugtracker`.`mantis_bug_history_table` `bh` inner join (select `bh`.`bug_id`, max(`bh`.`date_modified`)as `md` `bugtracker`.`mantis_bug_history_table` `bh` group `bh`.`bug_id`) `max_dates` on `bh`.`bug_id` = `max_dates`.`bug_id` , `bh`.`date_modified` = `max_dates`.`md` left join `bugtracker`.`mantis_bug_table` `b` on `bh`.`bug_id` = `b`.`id`
join max dates this:
select distinct ... `bugtracker`.`mantis_bug_history_table` `bh` inner join (select bug_id, max(date_modified) md mantis_bug_history_table group bug_id) max_dates on bh.bug_id = max_dates.bug_id , bh.date_modified = max_dates.md left join ...
for example , other ways solve this, here's excellent manual entry the rows holding group-wise maximum of column
Comments
Post a Comment