mysql select语句,该如何解决

mysql select语句

有一表ab内容如下

id name sex year

1 1 2011

2 ddd 0 2012

3 1 2011

4 1 2011

5 ggg 0 2012

6 1 2011

7 fff 1 2011

8 ggg 0 2012

9 1 2011

10 aaa 1 2000

11 1 2011

查找结果为

count(id),group_concat(niu)

11 ,aaa,ddd,,,ggg,,fff,ggg,,aaa,

这是我的语句:select count(id),group_concat(name) from ab

找出的结果里含有太多的逗号了,怎么去掉它啊?

理想的结果为:

count(id),group_concat(name)

11 aaa,ddd,ggg,fff,ggg,,aaa




有name是空看来

select count(id),group_concat(name) from ab where name is not null



SQL code


select count(*), substring_index(GROUP_CONCAT(name order by name desc),',,',1) from ab;


select count(id),group_concat(if(name is null or name='','',concat(name,',')) SEPARATOR '') from ab

+1 探讨
select count(id),group_concat(if(name is null or name='','',concat(name,',')) SEPARATOR '') from ab
mysql select语句,该如何解决

相关文章:

你感兴趣的文章:

标签云: