Can not I make this inquiry?

0

I want to add the values that are in VLR_TOTAL where NOMBRE equals Expansion and NOMBRE equals Mantenimiento.

I have the following query:

    SELECT SUM(VLR_TOTAL) FROM bodega_moviles WHERE NOMBRE = Expansion AND 
    NOMBRE = Mantenimiento

but throws me as a result

SUM(VLR_TOTAL)
 NULL
    
asked by Anderviver 31.08.2017 в 16:52
source

1 answer

3

Simple, change your operator AND to OR :

SELECT SUM(VLR_TOTAL) 
FROM bodega_moviles 
WHERE NOMBRE = 'Expansion' OR
NOMBRE = 'Mantenimiento'

By saying NOMBRE = [algún valor] AND NOMBRE = [algún otro valor] you are telling the query that the field NOMBRE should be equal to 2 different values, which can not be.

You can also use the IN operator in the following way to avoid redundancy:

SELECT SUM(VLR_TOTAL) 
FROM bodega_moviles 
WHERE NOMBRE IN ('Expansion', 'Mantenimiento')
    
answered by 31.08.2017 / 16:55
source