路过的瞧瞧 !!!!!(20分)

  • 主题发起人 主题发起人 admin2008
  • 开始时间 开始时间
A

admin2008

Unregistered / Unconfirmed
GUEST, unregistred user!
日期 &nbsp; &nbsp; &nbsp; &nbsp; ID码 &nbsp; &nbsp;入库量 &nbsp; 出库量 &nbsp; 库存量<br>2008-01-15 &nbsp; 1001 &nbsp; &nbsp; 10 &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; 9<br>2008-01-15 &nbsp; 1002 &nbsp; &nbsp; &nbsp; 8 &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; 13<br>2008-01-15 &nbsp; 1003 &nbsp; &nbsp; &nbsp;15 &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; 18<br>我想得出这样的结果当点查询按钮 在dbgrideh中显示<br>我是通过视图<br><br>ALTER &nbsp; &nbsp; &nbsp;view v_yaopin_GZ<br>as<br>select a.in_date as date,<br>'入库' as type,<br>b.mount as addmount,--入库数量<br>0 as lowmount,--出库数量<br>0 as cgmount,--库存数量<br>b.SYS_ID as sys_id,<br>a.in_id as bill_id,<br>d.yaoid as yaoid<br>from inhead a,inhouse b,yaoid d c<br>where a.in_id=b.in_id and b.yaoid=c.yaoid <br>union<br>select a.out_date as date,<br>'出库'as type,<br>0 as addmount,<br>b.mount as lowmount,<br>0 as cgmount,<br>b.SYS_ID as sys_id,<br>a.out_id as bill_id,<br>c.yaoid as yaoid<br>from Other_head a,Other_outhouse b, yaoid c<br>where a.out_id=b.out_id and b.yaoid=c.yaoid<br>现在就是库存数量算不出来,应怎么样得出如上图的结果呢 &nbsp;只能通过一张视图<br>当然可以另创建一张表 但这不妥
 
上面的发错了 应是这样的 <br>日期 &nbsp; &nbsp; &nbsp; &nbsp; ID码 &nbsp; &nbsp;入库量 &nbsp; 出库量 &nbsp; 库存量<br>2008-01-15 &nbsp; 1001 &nbsp; &nbsp; 10 &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; 9<br>2008-01-15 &nbsp; 1001 &nbsp; &nbsp; &nbsp; 8 &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; 13<br>2008-01-15 &nbsp; 1002 &nbsp; &nbsp; &nbsp;15 &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; 5
 
一个查询语句也可以解决,把你的结果加个括号,就可以再运算,不过你的语句太长懒得看;说第二种方法——视图嵌套,直接建立第二个视图 select x,x,x,x,库存量=x+x-x.. from v_yaopin_GZ就行。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
785
import
I
后退
顶部