我有一个总是需要比较4个值的MySQL查询,我需要使用UNION ALL将这些值添加到行中,但是这个代码看起来非常大,我想简化它。 代码如下:
SELECT
trimestre,
IF ((meta = 0) OR (meta is null) or not(meta REGEXP '[0-9]+'), :meta, meta) as valor
FROM
(
SELECT
trimestre,
valor AS meta
FROM
view_valores_indicadores
WHERE
anio = :anio
AND codigo_indicador = :codigo_indicador
AND alias_campo = 'meta'
UNION ALL
SELECT
1,
:meta
UNION ALL
SELECT
2,
:meta
UNION ALL
SELECT
3,
:meta
UNION ALL
SELECT
4,
:meta
ORDER BY
trimestre ASC
) AS T
GROUP BY
TRIMESTRE
我想知道是否可以简化多个UNION ALL,如
UNION ALL SELECT (row1, row1, row3...)