database - Mysql group by with normal column and mysql function aliases column -
i have been trying group mysql group in normal column , mysql function aliases column mysql function aliases wont work group query tried , should work according mysql documentation.
select `project`.`project_name`, sum(cost_allocated) cost_allocated, count(task_id) counttask, group_concat(task_registration.members separator ';') members, group_concat(task_registration.indicators separator ';') indicators, group_concat(task_registration.percent_complete separator ';') percent_complete, group_concat(task_registration.status separator ';') status, date_format(`task_registration`.`created_at`, '%m') month (`project`) inner join `task_registration` on `task_registration`.`project` = `project`.`project_id` group `task_registration`.`project`,`month` order `project`.`project_id` desc
now after removing normal column group , adding mysql function aliases column works fine need both
select `project`.`project_name`, sum(cost_allocated) cost_allocated, count(task_id) counttask, group_concat(task_registration.members separator ';') members, group_concat(task_registration.indicators separator ';') indicators, group_concat(task_registration.percent_complete separator ';') percent_complete, group_concat(task_registration.status separator ';') status, date_format(`task_registration`.`created_at`, '%m') month (`project`) inner join `task_registration` on `task_registration`.`project` = `project`.`project_id` group `month` order `project`.`project_id` desc
after removing task_registration`.`project
group
group `task_registration`.`project`,`month` doesnt work in case
http://sqlfiddle.com/#!2/18389/2 have tried far
very difficult work out want without table declarations, sample input data , sample output data, comment can suggest using 2nd query sub query , joining results of first query:-
select project.project_name, sum(cost_allocated) cost_allocated, count(task_id) counttask, group_concat(task_registration.members separator ';') members, group_concat(task_registration.indicators separator ';') indicators, group_concat(task_registration.percent_complete separator ';') percent_complete, group_concat(task_registration.status separator ';') status, date_format(task_registration.created_at, '%m') month, sub0.cost_allocated months_cost_allocated, sub0.counttask months_counttask, sub0.members months_members, sub0.indicators months_indicators, sub0.percent_complete months_percent_complete, sub0.status months_status (`project`) inner join `task_registration` on `task_registration`.`project` = `project`.`project_id` inner join ( select date_format(task_registration.created_at, '%m') month, sum(cost_allocated) cost_allocated, count(task_id) counttask, group_concat(task_registration.members separator ';') members, group_concat(task_registration.indicators separator ';') indicators, group_concat(task_registration.percent_complete separator ';') percent_complete, group_concat(task_registration.status separator ';') status (project) inner join task_registration on task_registration.project = project.project_id group `month` ) sub0 on date_format(task_registration.created_at, '%m') = sub0.`month` group task_registration.project, `month`, months_cost_allocated, sub0.counttask months_counttask, sub0.members months_members, sub0.indicators months_indicators, sub0.percent_complete months_percent_complete, sub0.status months_status order project.project_id desc
Comments
Post a Comment