SQL syntax error SUM ()

0

I have the following scenario:

A table of products ( tbl_prods ) that has, among other fields, the price of each product, the type of products and the date of the transaction (% with%). The types can be dt_trns , typ1 or typ3 .

I want a query that returns the sum of the prices of products sold for a given user in the year 2016 and in the month of 10, and if the product is type 2 (typ2) it should have a 40% / p>

This is what I have but it is not working:

SELECT SUM(IF(prodtype='typ2',price*0.6,price)) FROM tbl_prods WHERE userId=123 AND YEAR(dt_trns)=2016 AND MONTH(dt_trns)=12;

Result = typ3

Where am I going wrong?

    
asked by anonymous 06.10.2017 / 20:36

1 answer

0

An AS return_name was missing. The correct would be:

SELECT SUM(IF(prodtype='typ2',price*0.6,price)) as soma FROM tbl_prods WHERE userId=123 AND YEAR(dt_trns)=2016 AND MONTH(dt_trns)=12;
    
06.10.2017 / 20:45