I have a problem. I have the following tables in MySQL:
+---------+ +-----------+ +---------+
| USER | | USER_LANG | | LANG |
| id_user | | id_user | | id_lang |
| name | | id_lang | | name |
| | | years | | |
+---------+ +-----------+ +---------+
and I have the following information:
+--------------------------------+
| ID_USER | ID_LANG | YEARS |
| 1 | 5 | 1 |
| 1 | 6 | 2 |
| 2 | 5 | 9 |
| 2 | 6 | 3 |
| 3 | 5 | 7 |
+--------------------------------+
What I need to achieve is to group all users who speak exactly the same group of languages and sum the years. For example, I need to get is:
+----------------------+
| LANGS | SUM_YEARS |
| 5;6 | 15 |
| 5 | 7 |
+----------------------+
It is very strange, but I need this. I tried with GROUP_CONCAT but didn’t work.
Hopefully they can help me.
Thanks in advance.
That’s an unusual request, but it should work out with the
GROUP_CONCAT()inside a subquery: