有个库存表,结构如下
月份 名称 数量
1 cpu 5
1 主板 3
2 cpu 10
2 主板 4
3 cpu 2
3 主板 5
上表是每个月按月输入,输入后想要在数据库中保存成
下面的样子
月份 名称 数量
1 cpu 5
1 主板 3
2 cpu 15
2 主板 7
3 cpu 17
3 主板 12
有什么方法可以实现?
月份 名称 数量
1 cpu 5
1 主板 3
2 cpu 10
2 主板 4
3 cpu 2
3 主板 5
上表是每个月按月输入,输入后想要在数据库中保存成
下面的样子
月份 名称 数量
1 cpu 5
1 主板 3
2 cpu 15
2 主板 7
3 cpu 17
3 主板 12
有什么方法可以实现?
解决方案 »
- listview应用出现内存泄漏现象,大家来看看???
- 考验一下你的水平阿,大家帮忙!
- 在MDI字窗体中如何获取父窗体Name或者父窗体Caption等等
- popupmenu菜单焦点问题?
- 新手求教......
- 请问行家:intraweb是以前的Active Form吗????????????????
- 我在WIN98安装MSSQL个人版本,但老是安装不上,错误提示:,Provider cannot be found.it may not be properly installed;
- 调试Socket通讯程序报错!全天在线!!急!!
- 要回家,吐血送分!
- 来的有分给
- 两个DBGrid显示相关联的内容
- 求动态库调用源码工程
--测试数据库为oracle--测试表
create table test (c_month int,c_name varchar2(100),c_num int);
--测试数据
insert into test
select 1,'cpu',5 from dual union all
select 1,'主板',3 from dual union all
select 2,'cpu',10 from dual union all
select 2,'主板',4 from dual union all
select 3,'cpu',2 from dual union all
select 3,'主板',5 from dual;
--获得累计数函数
create or replace function getNum(cmonth int,cname varchar2) return int
is
num int;
begin
select nvl(sum(c_num),0) into num from test where c_month<=cmonth and c_name=cname;
return num;
end;
--执行查询
select c_month,c_name,getnum(c_month,c_name)
from test
group by c_month,c_name
--查询结果
1 cpu 5
1 主板 3
2 cpu 15
2 主板 7
3 cpu 17
3 主板 12
from 表
group by 月份,名称
SELECT t1.c_month,t1.c_name,(select sum(t.c_num) from test t where t.c_month<=t1.c_month and
t.c_name=t1.c_name) as sum
from test t1 group by t1.c_month,t1.c_name;
在你的库存表显示的结果应该算是一个入库记录表吧,入库时增加库存,你还应该有一个出库的记录表,出库时减库存。
按你想要的结果,应该是保存小于等于当前月的入库汇总信息,你可以每个月存一次。比如3月
insert into 表2
select 3,名称,sum(数量)
from 表1
group by 名称
create table test (c_month int,c_name varchar(100),c_num int)insert into test
select 1,'cpu',5 union all
select 1,'主板',3 union all
select 2,'cpu',10 union all
select 2,'主板',4 union all
select 3,'cpu',2 union all
select 3,'主板',5 select
c_month,
c_name,
isnull((select sum(c_num) from test where c_name=a.c_name and c_month<a.c_month),0)+c_num
from test a/*
c_month c_name
----------- ---------------------------------------------------------------------------------------------------- -----------
1 cpu 5
1 主板 3
2 cpu 15
2 主板 7
3 cpu 17
3 主板 12(所影响的行数为 6 行)
*/
在你的库存表显示的结果应该算是一个入库记录表吧,入库时增加库存
按你想要的结果,应该是保存小于等于当前月的入库汇总信息,你可以每个月存一次。
To:zxf_feng 阿日
就是你说的这个意思,每个月实现累加,一月就是一月的库存,二月是一月加二月的库存,三月是一月加二月加三月
但是往库存表中insert的时候总是提示当前提供程序不支持从单一执行返回多个记录集
adoquery.Open;替换成adoquery.ExecSQL