select quarter(d.订购日期) as 季度,sum (dm.单价*dm.数量*(case when dm.折扣 = 0 then 1 else (1-dm.折扣) end))as 销售额 from 订单 d join 订单明细 dm on dm.订单ID = d.订单ID group by order by 季度 错在那里
时间: 2023-12-31 09:03:52 浏览: 72
Quartus-13.0.0.156_Device,包含cyclonev-13.0.0.156
5星 · 资源好评率100%
应该将 `group by` 放到 `select` 语句的后面,而非 `order by` 的前面。正确的 SQL 语句应该是:
```
select quarter(d.订购日期) as 季度, sum(dm.单价 * dm.数量 * (case when dm.折扣 = 0 then 1 else (1 - dm.折扣) end)) as 销售额
from 订单 d
join 订单明细 dm on dm.订单ID = d.订单ID
group by quarter(d.订购日期)
order by 季度
```
这样才能按照季度来进行分组,并且按照季度的顺序进行排序。
阅读全文