Ejemplos group_concat

https://www.mysqltutorial.org/mysql-group_concat/

Sintaxis:

GROUP_CONCAT(
DISTINCT expression
ORDER BY expression
SEPARATOR sep
);


SELECT first_name,last_name,
group_concat(title order by title separator ' \\ ') films,
count(film.film_id) total
FROM actor join film_actor using(actor_id)
join film using(film_id)
group by actor.actor_id

SELECT title,
group_concat(first_name,' ', last_name
order by first_name,last_name separator ' \\ ') actors,
count(film.film_id) total
FROM actor join film_actor using(actor_id)
join film using(film_id)
group by film_id

SELECT title,
group_concat(concat(first_name,' ', last_name)
order by concat(first_name,' ', last_name) separator ' \\ ') actors,
count(film.film_id) total
FROM actor join film_actor using(actor_id)
join film using(film_id)
group by film_id

select title, group_concat(distinct rental_date order by rental_date desc separator ' - ')
from pagos_peliculas
where month(rental_date)=8
group by film_id;

Publicado por

Juan Pablo Fuentes

Formador de programación y bases de datos