提问人:Michael Turner 提问时间:10/31/2023 最后编辑:Michael Turner 更新时间:11/1/2023 访问量:45
我不知道如何格式化我的 FROM 语句以避免语法错误字符串文字
I don't know how to format my FROM statement to avoid syntax error string literal
问:
我不知道为什么SQL无法识别语句中的表名。它返回一个语法错误,指出预期的字符串文字“peak-bit-402819.warehouse_orders。订单“在 [7:10] 我试图在 FROM 语句中加入双引号,但无济于事。编辑:我添加了我使用的两个表格的细节图片。我还尝试使用详细的表名,并得到在美国找不到的相同错误。请看图片。FROM
SELECT
Warehouse.warehouse_id,
CONCAT(Warehouse.state, ":", Warehouse.warehouse_alias) AS warehouse_name,
COUNT(Orders.order_id) AS number_of_orders,
(SELECT COUNT(*)
FROM 'peak-bit-402819.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
'peak-bit-402819.warehouse_orders.Warehouse' 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
答:
0赞
Jumbalaya Bill
11/1/2023
#1
如果这些是实际的表名,您可以尝试使用括号来代替:
(SELECT COUNT(*)
FROM [peak-bit-402819.warehouse_orders.Orders] Orders) AS total_orders,
和
FROM
[peak-bit-402819.warehouse_orders.Warehouse] Warehouse
评论
peak-bit-402819.warehouse_orders
peak-bit-402819
[peak-bit-402819.warehouse_orders].[Warehouse]
"peak-bit-402819.warehouse_orders"."Warehouse"
.