已有22人关注
请教老师一个计算过程
发表在VB答疑区 2008-02-13
是否精华
版块置顶:
<P>我虽然学习了您们出版的几本VB书,但由于才疏学浅,现在遇到一个问题老是想不怎么写,不知老师是否可以指导一下。基本情况是这样的:</P>
<P><STRONG>产品1的结构:</STRONG></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 编码&nbsp;&nbsp;&nbsp;&nbsp; 数量&nbsp;&nbsp;&nbsp; 备注</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1103&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.5&nbsp;&nbsp;&nbsp; 低速</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2001&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .............</P>
<P><STRONG>产品2的结构:</STRONG></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 编码&nbsp;&nbsp;&nbsp;&nbsp; 数量&nbsp;&nbsp;&nbsp; 备注</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp; 中速</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1104&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp; 低速</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2001&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .............</P>
<P><STRONG>记录总表结构:</STRONG></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 产品名称&nbsp;&nbsp;&nbsp;&nbsp; 数量&nbsp;&nbsp;&nbsp;&nbsp; 要求</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 产品1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 低速</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 产品2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 中速</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; .............</P>
<P><STRONG>材料汇总表结构:</STRONG></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 编码&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 数量</P>
<P>&nbsp;&nbsp;&nbsp; 要实现的过程是:计算“记录总表”中所有产品的“备注”符合记录总表的“要求”和所有产品中“备注”为空的总数量,并存入“材料汇总表”。</P>
<P>&nbsp;&nbsp;&nbsp; 请老师指导一下,先谢谢了!</P>
分享到:
精彩评论 5
Lemon
学分:0 LV1
2008-02-15
沙发
<P>您好!</P>
<P>“记录总表”中没有“备注”字段。</P>
<P>请您将需要的查询结果也一并给出,即,根据您上面出给的数据表和数据,要求查询出的“材料汇总表”中的结构和数据都给出,我们看是否可以帮您解决。</P>
rjl0663
学分:0 LV1
2008-02-16
板凳
<P><FONT size=4><STRONG>刘老师,先谢谢您,我说得不是很清楚,其实“记录总表”的要求就相当于备注。像我这例子的计算过程就是将“产品1的数量(备注为空和低速的记录)×2 + 产品2的数量(备注为空和中速的记录)</STRONG><STRONG>”,材料汇总表的计算结果就是下面的结果。</STRONG></FONT></P>
<P><STRONG>产品1的结构:</STRONG></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 编码&nbsp;&nbsp;&nbsp;&nbsp; 数量&nbsp;&nbsp;&nbsp; 备注</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1103&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.5&nbsp;&nbsp;&nbsp; 低速</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2001&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .............</P>
<P><STRONG>产品2的结构:</STRONG></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 编码&nbsp;&nbsp;&nbsp;&nbsp; 数量&nbsp;&nbsp;&nbsp; 备注</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp; 中速</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1104&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp; 低速</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2001&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .............</P>
<P><STRONG>记录总表结构:</STRONG></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 产品名称&nbsp;&nbsp;&nbsp;&nbsp; 数量&nbsp;&nbsp;&nbsp;&nbsp; 要求</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 产品1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 低速</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 产品2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 中速</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; .............</P>
<P>&nbsp;</P>
<P><STRONG>材料汇总表结构:</STRONG></P>
<P><FONT color=#0909f7>&nbsp;&nbsp;&nbsp;&nbsp; 编码&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 数量</FONT></P>
<P><FONT color=#0909f7>&nbsp;&nbsp;&nbsp;&nbsp; 1101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9</FONT></P>
<P><FONT color=#0909f7>&nbsp;&nbsp;&nbsp;&nbsp; 1103&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3</FONT></P>
<P><FONT color=#0909f7>&nbsp;&nbsp;&nbsp;&nbsp; 2001&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 19</FONT></P>
Lemon
学分:0 LV1
2008-02-19
地板
<P>您好!</P>
<P>可以利用创建临时表的方法实现,下面的SQL语句可以实现您的功能,您尝试一下。</P>
<P>select 数量*2 as 数量 ,编码 <BR>into tb1<BR>from 产品1 where 备注 is NULL or 备注='低速'</P>
<P>select 数量,编码&nbsp; <BR>into tb2<BR>from 产品2 where 备注 is Null or 备注 ='中速'</P>
<P>select tb1.编码,(tb1.数量+tb2.数量)as 数量 from tb1,tb2 where tb1.编码=tb2.编码 </P>
<P>drop table tb1<BR>drop table tb2<BR></P>
rjl0663
学分:0 LV1
2008-02-19
4L
刘老师,像这样,如果有几十个产品记录(而且又不是固定的记录数),那不是要建很多的临时表吗?而“select tb1.编码,(tb1.数量+tb2.数量)as 数量 from tb1,tb2 where tb1.编码=tb2.编码”又该如何写?有没在更好的方法呢?谢谢!
Lemon
学分:0 LV1
2008-02-26
5L
<P>您好!</P>
<P>在有些情况下通过SQL语句不能直接实现的功能,可以利用在程序代码中设置中间的临时变量来实现。比如您说的那种情况,可以利用在SQL语句中的中间设置一些临时的变量,将数据表 或者产品名等都存储为变量,利用这些变量和原有的SQL语句来实现需要的功能。</P>
<P>像您说的这种情况,产品数不固定,又没有具体的规律可寻,就不太好分析了。</P>
首页上一页 1 下一页尾页 5 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照