Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Syntax error: Expected ")" but got keyword AS at [8:1]

I'm getting error again and again. Could anyone please help me with that. Any help would be much appreciated. Here is my code:

 

SELECT
warehouse.warehouse_id,
CONCAT(Warehouse_state, ':', Warehouse.warehouse_alias) AS warehouse_name,
COUNT(orders.order_id) AS number_of_orders,
(SELECT
COUNT(*)
FROM genuine-octagon-408302.warehouse_orders.orders Orders
AS total_orders,
CASE
WHEN COUNT(Orders.order_id)/(SELECT COUNT(*) FROM warehouse_orders.orders orders) <= 0.20
THEN "fulfilled 0-20% of Orders"
WHEN COUNT(Orders.order_id)/(SELECT COUNT(*) FROM warehouse_orders.orders orders) > 0.20
AND COUNT(Orders.order_id)/(SELECT COUNT(*) FROM warehouse_orders.orders orders) <= 0.60
THEN "Fulfilled 21-60% of Orders"
ELSE "Fulfilled more than 60% of Orders"
END AS fulfillment_summary
FROM genuine-octagon-408302.warehouse_orders.warehouse
LEFT JOIN warehouse_orders.orders Orders
ON Orders.warehouse_id = warehouse.warehouse_id
GROUP BY
Warehouse.warehouse_id,
warehouse_name
HAVING
COUNT(Orders.order_id) >0
Solved Solved
1 1 4,501
1 ACCEPTED SOLUTION

There’s a syntax mistake here. On line 8 of your query you have a missing closing bracket at the beginning of the line. It should be ) AS total_orders. Or you could move the ) to the end of line 7 depending on your styling.

This is because you have an open bracket starting on line 5 that needs to be closed before ending the calculation.

View solution in original post

1 REPLY 1

There’s a syntax mistake here. On line 8 of your query you have a missing closing bracket at the beginning of the line. It should be ) AS total_orders. Or you could move the ) to the end of line 7 depending on your styling.

This is because you have an open bracket starting on line 5 that needs to be closed before ending the calculation.