Skip to content

Instantly share code, notes, and snippets.

@Restoration
Created October 26, 2016 08:27
Show Gist options
  • Select an option

  • Save Restoration/04e27cab1248302938108b95caaabd83 to your computer and use it in GitHub Desktop.

Select an option

Save Restoration/04e27cab1248302938108b95caaabd83 to your computer and use it in GitHub Desktop.
mysql GROUP_CONCATで空データを削除

#mysql GROUP_CONCATで空データを削除

##Before

ID GROUP_CONCAT(VAL) 
1 ,64,66,,203,214,204

##After ID GROUP_CONCAT(VAL) 1 64,66,203,214,204

###置き換え

select id,replace(group_concat(val),',,',',') from test group by id

###ifで判定

select id,group_concat(if(val ='',null, val)) from test group by id

###Nullifを使用する

select id,group_concat(Nullif(val,'')) from test group by id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment