group concat - Issue with Mysql SUM and GROUP_CONCAT in query -


i having issue query having both sum , group_concat function.

the sum values changes group_concat values increases.

below code:

select     ul.display_name,             ul.photo,             ul.user_id,             sum(ulr.level_score)              level_scores,             sum(ulr.level_timer)              level_timer,             group_concat(ulr.level_completed) levels,             group_concat(distinct c.bit_id)   bit_id        user_level_responses              ulr  inner join user_login                        ul  on         (                        ul.user_id=ulr.user_id)  inner join c_member cm  on         (                        cm.user_id=ul.user_id             ,        cm.user_approval='y'             ,        cm.delete_status='0'             ,        cm.status='1')  inner join ctree ct  on         (                        cm.circuit_id=ct.circuit_id )  inner join cir c  on         (                        c.circuits_id=cm.circuit_id             ,        c.builtin=0             ,        c.delete_status='0'             ,        c.status='1')       match(ct.circuit_path) against ('_902_')  ,        ulr.institution_id=321  ,        ulr.delete_status=0  ,        ulr.status=1  ,        ul.delete_status=0  group   ulr.user_id  order   level_scores desc,             level_timer asc,             ul.display_name limit 500 

if actual score 900 , if have 2 ids in group_concat actual score double original.

expected output:  user1   2010.cs,btech   960 00:01:08    completed user2   btech   920 00:01:08    completed  output getting:  user1   2010.cs,btech   1920    00:01:08    completed user2   btech   920 00:01:08    completed 

twice actual amount ie 960.

your problem multiple ids doubling rows result has before grouping. can solve problem joining in of external data in subquery.

i have absolutely no idea structure of database, nor of functions, stab in dark @ reorganizing query. if need, can write simpler sqlfiddle show mean.

select     ul2.display_name,             ul2.photo,             ul2.user_id,             sum(ulr.level_score)              level_scores,             sum(ulr.level_timer)              level_timer,             group_concat(ulr.level_completed) levels,             ul2.bit_id       user_level_responses              ulr inner join (     select     ul.display_name,     ul.photo,     ul.user_id,     group_contact(distinct c.bit_id)  bit_id           user_login                        ul      inner join c_member cm      on         (                    cm.user_id=ul.user_id             ,        cm.user_approval='y'             ,        cm.delete_status='0'             ,        cm.status='1')      inner join ctree ct      on         (                    cm.circuit_id=ct.circuit_id )      inner join cir c      on         (                    c.circuits_id=cm.circuit_id             ,        c.builtin=0             ,        c.delete_status='0'             ,        c.status='1')           match(ct.circuit_path) against ('_902_')      ,        ul.delete_status=0     group   ul.user_id ) ul2 on  (         ulr.user_id = ul2.user_id )      ulr.institution_id=321  ,        ulr.delete_status=0  ,        ulr.status=1  group   ulr.user_id order   level_scores desc,             level_timer asc,             ul.display_name limit 500 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -