Having the following table:
Productos
_______________
id_producto
nombre_producto
tipo_especial
fecha_inclusion
I would like to obtain the product account conditioning whether or not it is a type special, by aliasing each resulting row, in order to later to be able to work separately the results avoiding making a query for each special_ type.
SELECT COUNT(*), nombre_producto, tipo_especial
FROM productos
WHERE tipo_especial = 1
AND fecha_inclusion "2018-03-12"
UNION
SELECT COUNT(*), nombre_producto
FROM productos
WHERE tipo_especial = 2
AND fecha_inclusion "2018-03-12"
Expected result:
| COUNT(*) | NOMBRE_PRODUCTO
producto_tipo_especial_1 | 1 | queso
producto_tipo_especial_2 | 5 | jamon
Result obtained
| COUNT(*) | NOMBRE_PRODUCTO
| 1 | queso
| 5 | jamon