在做一个进销存软件:
有商品表 Goods 和库存表 Stock
商品表字段:
Goodsid 商品编码 , Goodsname商品名称
001 A
002 B
003 C
004 D
005 E
.... ....
库存表字段:
Goodsid商品编码,Stockid仓库编码,Quantity库存数量
001 01 10
002 01 10
003 01 20
001 02 30
002 02 40
当选择仓库编码01 后查询所有商品在该仓库的库存,库存表中不一定包含所有商品的数据
即该表 Goodsid Goodsname Stockid Quantity
001 A 01 10
002 B 01 10
003 C 01 20
004 D 01 0
005 E 01 0
...................................
SQl语句该如何写???
有商品表 Goods 和库存表 Stock
商品表字段:
Goodsid 商品编码 , Goodsname商品名称
001 A
002 B
003 C
004 D
005 E
.... ....
库存表字段:
Goodsid商品编码,Stockid仓库编码,Quantity库存数量
001 01 10
002 01 10
003 01 20
001 02 30
002 02 40
当选择仓库编码01 后查询所有商品在该仓库的库存,库存表中不一定包含所有商品的数据
即该表 Goodsid Goodsname Stockid Quantity
001 A 01 10
002 B 01 10
003 C 01 20
004 D 01 0
005 E 01 0
...................................
SQl语句该如何写???
解决方案 »
- 请问,如何将无用的菜单项及其对应的磁盘文件一次性快速删除?
- 程序不定期出现鼠标移动到控件上窗台自动关闭,什么原因呢?
- 关于异常处理的问题
- 这条语句有点不明白!! 大家帮我看看
- d6自带的那个installshield express 3.03不会用!求助!
- 菜题~~线程相关..
- RAD Studio 2007 最新的12月更新包安装问题
- 很急:一个非常郁闷无比的问题,关于窗体的ShowModal显示方式问题 (苦恼中,不小心发到VC那边去了,搞得我最后的10都浪费了,现在没钱了
- PHP4delphi.zip下载--但不知怎么用
- Delphi 7编的服务安装到win7 64位后如何在桌面上弹出界面和运行另一个程序,比如记事本?
- MDI主窗体中如何捕获子窗体的"close"事件?
- 如何把汉字转化为ASCLL字节数组?DELPHI
测试数据
create table Goods(GoodID varchar(10) , GoodName varchar(100))
insert into Goods values('001' , 'A')
insert into Goods values('002' , 'B')
insert into Goods values('003' , 'C')
insert into Goods values('004' , 'D')
insert into Goods values('005' , 'E')
GOcreate table Stock (GoodID varchar(10) , StockID varchar(10), Quantity int)
insert into Stock values('001' , '01', 10)
insert into Stock values('002' , '01',10)
insert into Stock values('003' , '01',20)
insert into Stock values('001' , '02',30)
insert into Stock values('002' , '02',40)
GOSELECT G.GoodID, G.GoodName, ISNULL(S.StockID, '01') AS StockID, ISNULL(S.Quantity, 0) AS Quantity
FROM Goods G LEFT JOIN
Stock S ON G.GoodID = S.GoodID AND STOCKID = '01'
sql.add('select goods.goodsid,goods.goodsname,stock.stockid,stock.Quantity from goods,stock where goods.goodsid=stock.goodsid and stock.Stockid=''01''')
select goods.goodsid,goods.goodsname,isnull(stock.stockid,0) as stockid,isnull(stock.Quantity,0) as Quantity from goods left join stock on goods.goodsid=stock.goodsid and stock.Stockid='01'
from (select * from stock where stockid = '01') a
right join (select * from goods) b on a.goodsid = b.goodsid;'01' 处使用你需要的仓库号替换,代码未测试
再次多谢各位大哥支持!!