SQL高手帮帮忙啊,急坏了,好心人先谢了(25分)

  • 主题发起人 主题发起人 whwxh
  • 开始时间 开始时间
W

whwxh

Unregistered / Unconfirmed
GUEST, unregistred user!
入库表 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;出库表 &nbsp; <br>入库日期 &nbsp; &nbsp;商品 &nbsp;数量 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 出库日期 &nbsp; &nbsp;商品 &nbsp;数量<br>2008.12.12 &nbsp;牙膏 &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2008.12.15 &nbsp;牙刷 &nbsp;1<br>2008.12.12 &nbsp;牙刷 &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2008.12.15 &nbsp;牙膏 &nbsp;1<br>2008.12.13 &nbsp;牙刷 &nbsp; 1<br><br>怎样用SQL语句列出所有商品的库存数量? &nbsp;<br>select b.商品,sum(b.數量) as 庫存 from <br>(select 商品,數量 from 入庫表<br>union &nbsp;all <br>select 商品,數量*-1 as數量 from 出庫表) b group by 商品 &nbsp;<br>把上面的SQL语句改成interbase语句怎么写啊??interbase不支持 from 后带(select ..)
 
interbase没有用过,试试下面的语句好不好用吧<br><br>select a.商品, sum(a.数量) - isnull(sum(b.数量), 0)<br>from 入库表 a left join 出库表 b<br>on a.商品 = b.商品<br>group by a.商品
 
给括号内的select语句建立视图,然后对视图select
 
再不行就用临时表!!!!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
493
import
I
D
回复
0
查看
828
DelphiTeacher的专栏
D
后退
顶部