sql - Mysql Distinct select with replace -
i have following mysql select statement returns below result , battling result after.
select `tvshow`.`idshow` `idshow`,`tvshow`.`c00` `showname`, if(count(distinct `episode`.`c12`), count(distinct `episode`.`c12`),0) `totalseasons`, if(count(`episode`.`c12`),count(`episode`.`c12`),0) `totalepisodecount` ((((`tvshow` left join `tvshowlinkpath` on ((`tvshowlinkpath`.`idshow` = `tvshow`.`idshow`))) left join `path` on ((`path`.`idpath` = `tvshowlinkpath`.`idpath`))) left join `episode` on ((`episode`.`idshow` = `tvshow`.`idshow`))) left join `files` on ((`files`.`idfile` = `episode`.`idfile`))) group `tvshow`.`idshow` having (count(`episode`.`c12`) > 0)
select result
i trying 4th column have seasons listed in e.g "season 1,season 2,season 3"
i can the data need running following select
select distinct c12 episode idshow = 1
it returns following.
so thought use replace change results read "season1" not sure how return 1 string containing "seasin1,season2,season3" , add select statement @ top of view , bring together?
the result trying get(used photoshop idea)
just add group_concat(episode.c12)
additional column:
select `tvshow`.`idshow` `idshow`,`tvshow`.`c00` `showname`, if(count(distinct `episode`.`c12`), count(distinct `episode`.`c12`),0) `totalseasons`, if(count(`episode`.`c12`),count(`episode`.`c12`),0) `totalepisodecount`, `group_concat(episode.c12)` `seasons` ((((`tvshow` left join `tvshowlinkpath` on ((`tvshowlinkpath`.`idshow` = `tvshow`.`idshow`))) left join `path` on ((`path`.`idpath` = `tvshowlinkpath`.`idpath`))) left join `episode` on ((`episode`.`idshow` = `tvshow`.`idshow`))) left join `files` on ((`files`.`idfile` = `episode`.`idfile`))) group `tvshow`.`idshow` having (count(`episode`.`c12`) > 0)
see http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat documentation of mysql specific function.
Comments
Post a Comment