Ⅰ sql语句查询今年单价总金额
年,季,月,周,天,小时
也就是说你要的是这个六个分别的金额与汇总。
按照从大到小,如果仅仅是按照现有的表来操作,那么个人觉得毫无疑问的要查6遍,每次汇总都是一遍,如果数据量大的话毫无疑问的卡死。
个人觉得可以先改造一下表,将时间字段分成这六个部分,然后分组的时候加上rollup,只要注意书写顺序,那么一次应该就可以了。这是我能想到的减小运算量的一个办法。
Ⅱ SQL 怎么按时间汇总累计金额
select 日期,sum(金额) 金额 from 表名 group by 日期
Ⅲ 请问一下,SQL按日期查询,查询每一天之前的金额总和
按天累计么?
select 日期, (select sum(金额) from tb where 日期<t.日期) 日累计金额
from tb t
Ⅳ SQL高手前来 怎么用SQL 语句实现 3个列 金额总和的相加 给我代码就好 在线等候。
用sum加不就行了?如下
declare @t table (a money,b money,c money)
insert into @t
SELECT 100,300,420 union all
SELECT 43,35,33 union all
SELECT 80,2,1
SELECT sum(a) as a,sum(b) as b,sum(c) as c,sum(a+b+c) as total from @t
Ⅳ sql语句求和
SQL中求和语句分为纵向汇总和横向汇总语句;
假设数据列为:A、B、C、D、E、F、G
纵向汇总语句:
selectsum(A),sum(B),sum(C),sum(D),sum(E),sum(F),sum(G)from表名
横向汇总的SQL语句是:
selectA,B,C,D,E,F,G,A+B+C+D+E+F+Gfrom表名
求所有数据总和的SQL语句是:
selectsum(A)+sum(B)+sum(C)+sum(D)+sum(E)+sum(F)+sum(G)from表名
结构化查询语言是高级的非过程化编程语言,允许用户在高层数据结构上工作。它不要求用户指定对数据的存放方法,也不需要用户了解具体的数据存放方式,所以具有完全不同底层结构的不同数据库系统, 可以使用相同的结构化查询语言作为数据输入与管理的接口。
(5)sql每天金额加总扩展阅读:
sql参考语句
删除新表
drop table tabname
增加一个列
Alter table tabname add column col type
添加主键
Alter table tabname add primary key(col)
删除主键
Alter table tabname drop primary key(col)
创建索引
create [unique] index idxname on tabname(col….)
Ⅵ sql按照时间查询金额的总和。如2013-8-14,计算出08-01到这一天总的和。时间是变化的,为datetime 类型。
时间是变化的,为datetime 类型。就相当于是有一个变量的东西吧。
declare @d_date datetime
set @d_date = '2013-08-14' --自己可以设置的时间
declare @d_start datetime
set @d_start = convert(varchar(8),@d_date,120) + '01'表 --计算每月第一天
select sum( 总金额) from 表
where 日期 between @d_start and @d_date
Ⅶ sql怎么将当月每一天的数据相加,求总和
insertintobartext(time,electricity)VALUES('2/2/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/3/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/4/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/5/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/6/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/7/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/8/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/9/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/10/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/11/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/12/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/13/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/14/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/15/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/16/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/17/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/18/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/19/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/20/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/21/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/22/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/23/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/24/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/25/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/26/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/27/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('2/28/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/1/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/2/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/3/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/4/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/5/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/6/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/7/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/8/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/9/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/10/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/11/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/12/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/13/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/14/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/15/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/16/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/17/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/18/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/19/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/20/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/21/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/22/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/23/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/24/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/25/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/26/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/27/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/28/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/29/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/30/2019',cast(floor(rand()*150)asint))
insertintobartext(time,electricity)VALUES('3/31/2019',cast(floor(rand()*150)asint))
Ⅷ 如何用sql统计总金额
1、如果你是要统计当日销售总金额,如下:
select
sum(piece*price)
as
'当日销售总额'
from
当日销售表
where
date='07/5/16'
2、如果你是要统计各商品当日的销售额,如下:
select
rq,sno,sname,sum(piece)
as
piece,sum(piece*price)
as
'销售额'
from
当日销售表
group
by
rq,sno,sname
Ⅸ sql统计某一表的某字段的总值(sum)
group
by
后面跟的字段必须是Select后面不是聚合函数的字段,少一个都不行。select后面不是聚合函数的字段都是分组依据(几个字段同时相等才会分在一组里统计)
下面这句是按帐户分组统计(帐户一样的消费金额相加):
select
账户,sum(消费金额)
as
总金额
from
表
group
by
账户
而你给的代码是按你N个字段统计,结果肯定不对。
若还想显示其他字段,用下面的语句:
select
x.账户,消费日期...(你的其他字段),总金额
from
表
x,(select
帐户,sum(消费金额)as
总金额
from
表
group
by
账户)
as
y
where
x.帐户=y.帐户
Ⅹ 能否用一句SQL同时查询本日和本月金额总值
本月的直接加,本日的用case when来加,脚本实例如下,以oracle为例:
selectsum(金额)本月的金额总数,
sum(casewhen日期字段>=trunc(sysdate)then金额else0end)今日的金额总数
from表名
where日期字段>=trunc(sysdate,'mm')
在sqlserver中case when 语法与上面一致:
selectsum(金额)本月的金额总数,
sum(casewhen日期字段>=cast(convert(varchar,getdate(),112)assmalldatetime)then金额else0end)今日的金额总数
from表名
where日期字段>=cast(convert(varchar(6),getdate(),112)+'01'assmalldatetime)