I’m using SQLite in my project and I need to write SQL query to retrieve total cost of the customer’s order. Here is the query:
SELECT SUM(g.cost * og.amount)
* (CASE om.include WHEN 0 THEN 0.0 ELSE m.markup_pct / 100) total_cost
FROM goods g JOIN orders_goods og ON g.good_id = og.good_id
JOIN orders_markups om ON om.order_id = og.order_id
JOIN markups m ON om.markup_id = m.markup_id
AND om.view_class_id = m.markup_id
WHERE og.order_id = 0;
But when I execute the above query on my database via sqlite3 it complains:
Error: near line 1: near ")": syntax error
Do you have any idea what’s wrong with script?
Any help will be appreciated.
P.S.: I don’t attach database structure because the error is syntactic, so the error is unrelated to the structure of DB.
There’s a syntax error in the case statement: it’s missing the
END: