我不确定是否已经存在这样的问题,找不到我的解决方案,如果这是重复的,很抱歉:我有一张带日期的表格:
|date (date)| tax (numeric) | (stuff in brackets is the type)
|2012-12-12 | 5.00 |
|2012-12-12 | 10.00 |
|2012-12-13 | 2.00 |
我希望我的输出看起来像这样:
|date (date)| tax (numeric) | (stuff in brackets is the type)
|2012-12-12 | 15.00 |
|2012-12-13 | 2.00 |
我正在考虑进行 CTE 类型查询,因为在数据库中,我将内容存储为没有时区的日期时间,以及一堆税这是我查询的开始:
with date_select as
(
select CAST(r.datetime as DATE), sum(r.tax) as tax
from suezensalon.receipt r
where r.datetime between '2012-12-12 00:00:00' and '2012-12-18 23:59:59'
group by r.datetime
order by r.datetime
)
这给了我最高的桌子。做这个的最好方式是什么?是通过“平均日期”吗?