Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何计算某一天的总账单金额?_Sql - Fatal编程技术网

Sql 如何计算某一天的总账单金额?

Sql 如何计算某一天的总账单金额?,sql,Sql,我有一个数据库表,其中有一个字段账单金额,它保存了特定人员的账单金额和另一个字段账单日期的记录。现在,我想显示某一天(例如今天)所有人的总账单金额,以生成日常销售报告。对于某一天,您可以运行以下命令,将日期更改为运行报告的任何日期 select sum(billed_amount) from tbl where billing_date = '2014-07-19' 请注意,每个数据库的默认日期格式各不相同。(您没有指定数据库) 要获取每个日期的总计(“按日期分组”),可以使用以下命令: se

我有一个数据库表,其中有一个字段账单金额,它保存了特定人员的账单金额和另一个字段账单日期的记录。现在,我想显示某一天(例如今天)所有人的总账单金额,以生成日常销售报告。

对于某一天,您可以运行以下命令,将日期更改为运行报告的任何日期

select sum(billed_amount)
from tbl
where billing_date = '2014-07-19'
请注意,每个数据库的默认日期格式各不相同。(您没有指定数据库)

要获取每个日期的总计(“按日期分组”),可以使用以下命令:

select billing_date, sum(billed_amount)
from tbl
group by billing_date
order by billing_date

您可以
天分组,并
合计
账单金额:

select  cast(billing_date as date)
,       sum(billing_amount)
from    YourTable
group by
        cast(billing_date as date)

日期操作因数据库而异。在SQL Server 2008+中,您可以将
日期时间
强制转换为
日期
类型以去除时间。

我使用的数据库是SQL Server management studio 2008 R2