Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/0/d542598456/htdocs/clickandbuilds/RidersOfTheBit/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 263
August | 2009 | Riders Of The Bit

Monthly Archives: August 2009

Funciones de agregación para valores no numéricos.

Las funciones de agregación se utilizan habitualmente, en SQL, durante la agrupación de resultados para mostrar sumatorios, estadísticas, etc. Pero puede ser que necesitemos obtener una concatenación de strings a partir de una agrupación. En MySql la solución viene de la mano de la función de agregación GROUP_CONCAT. La función acepta como parámetro una sintaxis basado en SQL para seleccionar el campo que se quiere concatenar, el separador a utilizar e incluso si hay que ordenar el resultado o mostrar valores no repetidos.

Ejemplo:

SELECT idPregunta, nombre, `email`, fecha, pregunta, GROUP_CONCAT(
    DISTINCT respuesta ORDER BY idRespuesta SEPARATOR ', '
)
FROM Respuestas
WHERE bloqueRespuestas = 'BqcjWf8en'
GROUP BY idPregunta /*, nombre, `email`, fecha, pregunta*/;

En el ejemplo se puede ver una consulta para recuperar las preguntas a un cuestionario y las posibles respuestas concatenadas en un string. Lo más curioso es como, a diferencia de la agrupación normal (con enteros), en este caso no hace falta agrupar por todos los campos proyectados en la consulta. Únicamente por el campo que se desea agrupar.