我的SQL代码不工作(在"FROM"处或附近出现语法错误(我需要最后一张桌子是三排。我从"总计"列创建的三个总计组的standard_amt_usd的平均值。我的错在哪里?
select avg(orders.standard_amt_usd), orders.total
, case when orders.total between 1 and 100 then "1 to 100"
when orders.total between 101 and 300 then " 101 to 300"
else " +500 "
FROM orders;
group by total
在所有案例之后尝试使用END
语句。
像这样:
SELECT AVG(orders.standard_amt_usd), orders.total,
CASE
WHEN orders.total BETWEEN 1 AND 100 THEN '1 to 100'
WHEN orders.total BETWEEN 101 AND 300 THEN '101 to 300'
ELSE '+500'
END AS OrderTotals
FROM orders
GROUP BY total;
评论:
- 始终将单引号(
'
(与SQL一起使用,而不是使用双引号("
( - 您的分号位于
FROM
语句的末尾。把它放在GROUP
之后,就像我上面做的那样
请参阅此