Foxtable(狐表)用户栏目专家坐堂 → sql语句求教


  共有16054人关注过本帖树形打印复制链接

主题:sql语句求教

帅哥哟,离线,有人找我吗?
雪山飞狐
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:13 积分:166 威望:0 精华:0 注册:2008/9/20 14:02:00
  发帖心情 Post By:2009/10/23 23:54:00 [显示全部帖子]

内部表SQL:
select a.型号,IIF(b.数量 is null,0,b.数量) +IIF(d.数量 is null,0 ,d.数量)  as 出库,IIF(f.数量 is null,0 ,f.数量) as 入库 from ((({kc} as a
left join (select 型号,sum(数量) as 数量 from {表A} group by 型号) as b on a.型号=b.型号) 
left join (select c.型号,sum(c.数量) as 数量 from (select 型号,数量 from {jh} where 状态='出库' or  状态='暂借') as c group by c.型号) as d on a.型号=d.型号 )
left join (select e.型号,sum(e.数量) as 数量 from (select 型号,数量 from {jh} where 状态='入库' or  状态='归还') as e group by e.型号) as f on a.型号=f.型号)

外部表SQL:
select a.型号,isnull(b.数量,0) +isnull(d.数量,0)  as 出库,isnull(f.数量,0) as 入库 from kc as a
left join (select 型号,sum(数量) as 数量 from 表A group by 型号) as b on a.型号=b.型号
left join (select c.型号,sum(c.数量) as 数量 from (select 型号,数量 from jh where 状态='出库' or  状态='暂借') as c group by c.型号) as d on a.型号=d.型号 
left join (select e.型号,sum(e.数量) as 数量 from (select 型号,数量 from jh where 状态='入库' or  状态='归还') as e group by e.型号) as f on a.型号=f.型号
[此贴子已经被作者于2009-10-23 23:55:21编辑过]

 回到顶部