如何明智地计算列的总和
How do sum of column with date wise
我在 table 中有以下数据:
qty dttime
15.83 2015-04-28 18:58:25.000
3.78 2015-04-28 18:58:27.000
29.39 2015-04-28 18:59:41.000
25.6 2015-04-29 19:01:23.000
2.39 2015-04-29 19:04:24.000
8.9 2015-04-30 19:07:25.000
8.18 2015-04-30 19:10:32.000
1.92 2015-04-30 19:13:48.000
现在我想明智地计算数量的总和并显示如下输出:
qty dttime
49 2015-04-28
27.99 2015-04-29
19 2015-04-30
我如何对所有这些数据求和并按日期排序?
您可以使用 date
数据类型提取日期(自 SQL Server 2008 起)。剩下的只是聚合:
select cast(dttime as date) as dte, sum(qty)
from t
group by cast(dttime as date)
order by dte;
使用cast()
:
select sum(qty) qty, cast(dttime as date) dttime
from table t
group by cast(dttime as date);
我在 table 中有以下数据:
qty dttime
15.83 2015-04-28 18:58:25.000
3.78 2015-04-28 18:58:27.000
29.39 2015-04-28 18:59:41.000
25.6 2015-04-29 19:01:23.000
2.39 2015-04-29 19:04:24.000
8.9 2015-04-30 19:07:25.000
8.18 2015-04-30 19:10:32.000
1.92 2015-04-30 19:13:48.000
现在我想明智地计算数量的总和并显示如下输出:
qty dttime
49 2015-04-28
27.99 2015-04-29
19 2015-04-30
我如何对所有这些数据求和并按日期排序?
您可以使用 date
数据类型提取日期(自 SQL Server 2008 起)。剩下的只是聚合:
select cast(dttime as date) as dte, sum(qty)
from t
group by cast(dttime as date)
order by dte;
使用cast()
:
select sum(qty) qty, cast(dttime as date) dttime
from table t
group by cast(dttime as date);