-1

I have a table from which I generate a view Grouping By Year and summing the amounts, and I wonder if I could somehow include a "string sum" or "string concatenation" of the aggregated dates or months.

Example: this is the base table

ID | date | year | month | amount

This is the actual view

ID | year | sum(amount)

what I am looking for is an additional field with concatenates the months to 03,05,11 (for example or to something similar), if a year aggregates data from march, may and november

ID | year | sum(amount) | list_of_months

Is that possible or do I have to create helping views to aggregate that?

Edit: I was able to answer myself: Group_concat to the help as shown in the answer below

2
  • Please run show create table tableName and add the output on the question in text format. Add some data examples and expected result Commented Oct 31 at 15:52
  • Sorry I forgot to format the table-headers and it was badly legible. Nevertheless the example is so simple that with minor abstract thinking it should be possible. Also I was able to answer myself: I was looking for GROUP_CONCAT ('column' SEPARATOR ',') AS 'list_of_months' Commented Nov 1 at 16:08

1 Answer 1

0

Group_Concat to the help

    SELECT 
    ...
    year,
    SUM(`amount`) AS `sum(amount)`,
    GROUP_CONCAT(`month` SEPARATOR ',') AS `list_of_months`
    ...
    FROM ...
    WHERE ...
    GROUP BY 'year'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.