Created
May 29, 2012 20:41
-
-
Save elhoyos/2830593 to your computer and use it in GitHub Desktop.
Sort by two factors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Todos los artículos de 'RAFA' primero ordenados por serial y luego el resto de artículos ordenados igualmente por serial. | |
SELECT a.* FROM articulos a LEFT JOIN (SELECT 'RAFA' COLLATE utf8mb4_general_ci AS nombre) r on r.nombre = a.usuario | |
ORDER BY r.nombre DESC, serial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Base de datos: `pruebas` | |
-- | |
-- -------------------------------------------------------- | |
-- | |
-- Estructura de tabla para la tabla `articulos` | |
-- | |
CREATE TABLE `articulos` ( | |
`id` int(11) NOT NULL, | |
`serial` varchar(50) DEFAULT NULL, | |
`usuario` varchar(50) DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
-- | |
-- Volcado de datos para la tabla `articulos` | |
-- | |
INSERT INTO `articulos` (`id`, `serial`, `usuario`) VALUES | |
(1, 'A', 'RAFA'), | |
(2, 'B', 'JUAN'), | |
(3, 'F', 'JAIME'), | |
(4, 'C', 'JAIME'), | |
(5, 'D', 'JUAN'), | |
(6, 'E', 'RAFA'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment