Created
January 9, 2013 11:29
-
-
Save kakobotasso/4492453 to your computer and use it in GitHub Desktop.
Case When - MySQL
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
SELECT a.idanuncio, | |
a.titulo, | |
a.estado, | |
(CASE WHEN a.preco_machos = 0 AND a.preco_femeas != 0 THEN a.preco_femeas WHEN a.preco_femeas = 0 && a.preco_machos != 0 THEN a.preco_machos WHEN a.preco_machos <= a.preco_femeas THEN a.preco_machos ELSE a.preco_femeas END) as preco, | |
ga.titulo AS imagem, | |
a.identificacao | |
FROM anuncio AS a | |
INNER JOIN galeria_anuncio AS ga ON a.idanuncio = ga.idanuncio | |
WHERE ga.posicao = 0 | |
GROUP BY a.idanuncio | |
ORDER BY a.idanuncio DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment