存储过程求和
A. oracle 在存储过程中加入对加工后的工资从小到大排序,并求和然后把所有结果放入一张表中
在close cur_1后面腔搭姿加一伍绝句
execute immediate 'create table temp_payroll_'枝乎||to_char(trunc(sysdate),'yyyymmdd')||' as
select emp_no,emp_date,emp_salary,sum(emp_salary) over(order by 1) salecount from payroll order by emp_salary asc';
B. 如何在mssql编写两个字段相乘后求和的存储过程,条件是当天。谢谢各位大侠!
这,,,跟存储过程没什么关系吧
sql就可以算出来
select o.产品名称,sum(o.数量*p.价格*o.折扣) from 订单表 o
left join 产品表 p on o.产品ID=p.产品ID
where o.订单日期=(date_format(now(), '%Y%m%d%') or 选择的日期)
and (o.客户编号='' or o.客户编号=选择的客户)
group by o.产品名称
C. 如何在存储过程中实现两个字段相加,然后存在第三个字段中,急急急急
说的不明白啊,两个字段相加,有数字求和的,有字符左右连接在一起的,对于哗裤第一种情况,步骤为:创建存储过程、定义输出参数、编写过程体、声明参数(用语存放结果)、乱亩简执行存储过程。具体代码如下:
create proc addfiled
@add int output
as
select @add=sum(f1+f2) from table1 where...
declere @nadd int output
exec pro addfiled @nadd
至于第二种情况,就需要进行左右连接了,比如将china和news合耐氏并成chinanews。楼主若有此需要请提出来,我再补上。
D. 存储过程求和
这样改一下:
reate procere cx_xsb @零食编号 char (5) as
declare @数量 varchar(10)
select @数量=sum(销售数量) from 销售表
where 零食编号=@零食编号 and year(销售日期)=year(getdate())
group by 零食编号
select @零食编号+'在'+datename(yy,getdate())+'敏稿年桥余孝的销售总毁并量为'+@数量
go
试一下
E. SQL 存储过程求和,求同比,请高手解答!
以A表为例子
先建燃雀团立一个table0
create table_0
(n_date date,
sheng varchar2(20),
sale number
tongbi number);
create unique index table_0_U1 on table_0 (n_date,sheng);
create or replace package body pkg_b_tongji is
procere sp_update_party_rating(p_sdate number, p_edate number) is
v_sdate date default to_date(p_sdate,'yyyymmdd');
v_edate date default to_date(p_edate,'yyyymmdd');
v_sqlUpd varchar2(3000);
v_sqlIns varchar2(3000);
begin
v_sqlIns := 'insert into table_0(n_date,sheng,sale)
values(:v1,:v2,:v3)';
v_sqlUpd := '皮橘update table_0 t set sale = :v1
where n_date = :v2 and sheng = :v3';
for c1 in (select a.ndate,
a.sheng,
sum(sale) sale
from a
where ndate between v_sdate and v_edate
group by a.ndate,
a.sheng
)
loop
execute immediate v_sqlUpd using c1.sale;
if sql%rowcount<=0 then --如果更新操作没有执行岁镇就执行插入操作
execute immediate v_sqlIns using c1.n_date,c1.sheng,c1.sale;
end if;
end loop;
commit;
end sp_update_party_rating;
---更新同比
procere sp_update_tongbi is
begin
for c2 in (
select n_date,
sheng,
sale,
nvl(sale,0) sale1
from table_0 a
left join
(select n_date,sheng,a.nvl(sale,0) sale
from table_0 a,
(select t.n_date,sheng
add_months(n_date,-1) n_date2
from table_0 t)
where a.sheng = b.sheng and a.n_date = b.n_date2)
)
loop
update table_0
set tongbi = sale/sale1
where n_date = c2.n_date and sheng = c2.sheng;
commit;
end loop;
end sp_update_tongbi;
end pkg_b_tongji;
F. SQL server 创建存储过程,要求该存储过程能够实现对输入的两个数相加,并将结果输出。。
一、创建
create proc p_sum
(@a int,
@b int,
@c int output)
as
set @c=@a+@b
--执行
declare @c int
exec p_sum 11 ,2 ,@c output
print @c
二友猜、create proc p_multiply(@a int=0,@b int=0,@c int output)
as
begin
set @c=@a*@b
end
--调用
--declare @a int,@b int,@c int
--select @a=3,@b=2
--exec p_multiply @a,@b,@c output
--select @c
(6)存储过程求和扩展阅读:
例子:
CREATE PROCEDURE order_tot_amt
@o_id int,
@p_tot int output
AS
SELECT @p_tot = sum(Unitprice*Quantity)
FROM orderdetails
WHERE orderid=@o_id
GO
例子说明:该例子是建立指没一个简单的存储过程order_tot_amt,这个存储过程根据用户输入的订单ID号码(@o_id),由订单明细表 (orderdetails)中计算该订单销售总额[单价(Unitprice)*数量(Quantity)],这一金额通过@p_tot这一参数输出给调用这一存好逗型储过程的程序。
G. 怎么用sql存储过程来跨行求和并且插入到数据库中,急用,跪谢啦
跨行求和,判断rownum(oracle)或者类似的参数的奇数偶数即可吧。
H. oracle怎么在存储过程中对表进行排序求和
排序用order by ,求和用sum 跟普通sql一样,只要把获得的值赋给变量就可以拿来使用了
I. mssql 求一个求和的存储过程
不推荐楼耐做芹镇主用法,也可以改昌首衡为
create PROCEDURE [dbo].[Pro_select_sum]
(
@WebId int
)
AS
declare @websum int
begin
Select @websum=ViewSum+InitPV from WebSites WHERE Webid=@webid
RETURN (@websum)
end
推荐用:
create PROCEDURE [dbo].[Pro_select_sum]
(
@WebId int
)
AS
begin
Select ViewSum+InitPV from WebSites WHERE Webid=@webid
end
go
create PROCEDURE [dbo].[Pro_select_sum]
(
@WebId int,@websum int output
)
AS
begin
Select @websum=ViewSum+InitPV from WebSites WHERE Webid=@webid
end
go
J. ORACLE利用存储过程求和
一句话就搞定了,烂迹不用过程
Select Sum(no)
From (Select Regexp_Substr('2,3,4,5', '[^,]+'饥腔并, 1, Level) no
From Dual
Connect By Level <=
Length('2,3,4,5') - Length(Replace('2,3,4,5', '圆灶,')) + 1)