Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Mysql Query with Case

$
0
0
Hello guys,

look I'm a beginner in the world of DBS, that means I'm an student so I'm dealing with a query which is giving me an error so I'd like some help in order to see what my mistake is at, here is the query and the result when I execute it:

Quote:

[SQL]SELECT
C.CompanyName AS Cliente,
C.City AS Ciudad,
P.ProductName AS Producto,
C.Country AS Pais,
Sum(OD.Quantity*OD.UnitPrice) AS Compra,
CASE
WHEN SUM(OD.Quantity*OD.UnitPrice)>=300 THEN "Fiel"
WHEN SUM(OD.Quantity*OD.UnitPrice)>=100 THEN "Potencial"
WHEN SUM(OD.Quantity*OD.UnitPrice)<100 THEN "Simpatizante"
END CASE AS Cliente_tipo
FROM
customers AS C
INNER JOIN orders AS O ON O.CustomerID = C.CustomerID
INNER JOIN `order details` AS OD ON OD.OrderID = O.OrderID
INNER JOIN products AS P ON OD.ProductID = P.ProductID
WHERE
C.Country IN ('Mexico', 'Argentina', 'Canada', 'Brazil', 'USA', 'Venezuela')
GROUP BY
C.CompanyName,
C.City,
P.ProductName,
C.Country

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE AS Cliente_tipo
FROM
customers AS C
INNER JOIN orders AS O ON O.Customer' at line 11
Any help would be really appreciated!

Viewing all articles
Browse latest Browse all 13329

Trending Articles