Problem in Select dates and amounts

0

Boys I have a problem that I have not been able to solve

This is my query to the bd

SELECT DATE_FORMAT( date, '%c' ) AS fecha, SUM( COALESCE( grand_total, 0 )) as total FROM sma_sales WHERE DATE_FORMAT(date, '%Y') = '2018' AND customer_id = 10 OR customer_id = 21 OR customer_id = 23 OR customer_id = 30 OR customer_id = 37 GROUP BY date_format( date, '%c' ) ORDER BY date_format( date, '%c' ) ASC

but it throws me wrong data, to make the same query with the IDs separately the amount is correct, but to take all the data together it goes crazy the amount that gives at the end

the total per user making the query one in one of the ids for November 2018 gives 19,924,349, but when making the complete query the result for November 2018 is 34.854.349

Any ideas?

    
asked by Octavio Santelices 04.12.2018 в 14:27
source

1 answer

0

I think you have to add parentisis nothing more:

SELECT DATE_FORMAT( date, '%c' ) AS fecha, SUM( COALESCE( grand_total, 0 )) as total 
FROM sma_sales 
WHERE DATE_FORMAT(date, '%Y') = '2018' 
AND (customer_id = 10 OR customer_id = 21 OR customer_id = 23 OR customer_id = 30 OR customer_id = 37) 
GROUP BY date_format( date, '%c' ) 
ORDER BY date_format( date, '%c' ) ASC

It could also have been written as:

SELECT DATE_FORMAT( date, '%c' ) AS fecha, SUM( COALESCE( grand_total, 0 )) as total 
FROM sma_sales 
WHERE DATE_FORMAT(date, '%Y') = '2018' 
AND customer_id in (10 , 21, 23, 30, 37) 
GROUP BY date_format( date, '%c' ) 
ORDER BY date_format( date, '%c' ) ASC
    
answered by 04.12.2018 / 15:08
source