Search code examples
mysqlmysql-error-1111

mysql group concat


how can I group concat? here is my query

select t.date, group_concat(count(*)) from table1 t
group by t.date

but it returns error "Invalid use of group function"

If I use query like this

select t.date, count(*) from table1 t
group by t.date

then it returns following output but I want to group_concat this output

2011-01-01  100
2011-01-02  97
2011-01-03  105

Solution

  • SELECT GROUP_CONCAT(`cnt` ORDER BY `date`) 
    FROM (
        SELECT t.`date`, COUNT(*) AS `cnt`
        FROM `table1` t
        GROUP BY t.`date`
    ) d