http://404278454.qzone.qq.com/

一道经典的数据库的笔试题目

上一篇 / 下一篇  2008-12-08 13:27:45 / 个人分类:数据库

一道数据库笔试题目

51Testing软件测试网7yH z~{+t(f F
51Testing软件测试网kz o2fUK
有两个表51Testing软件测试网YZSa2ub'fNA
51Testing软件测试网L4YY&}-e5a/@\
表一 AAA51Testing软件测试网-]Sv8zN"pr(ZZ
种类mc        库存总量s151Testing软件测试网 e+su4p!F9F
A        997       
"nYU1B)Lyx0B        123451Testing软件测试网\`S5m:zT

3b&U1u4Jy(l0表二         BBB51Testing软件测试网hn n9{^"m,{^
种类mc        出库数量s151Testing软件测试网Y WJ.|a
A        10551Testing软件测试网Rjz z'`R
A        21351Testing软件测试网p$v1i;M t6r&l Oh
B        11651Testing软件测试网-hL]2O f6ud
B        21151Testing软件测试网\ u!}ttX
B        30351Testing软件测试网2_ i&m(aJ.c f:D&Z?
用一条SQL语句求出A,B各剩下多少?

TAG: 数据库 笔试 题目

引用 删除 sfpl2009   /   2009-06-18 07:46:32
declare @t1 table(mc varchar(10), s1 int)
declare @t2 table(mc varchar(10),s1 int)
insert @t1
select 'a', 997
union all select 'b', 1234
insert @t2
select 'a', 105
union all select 'a', 213
union all select 'b', 116
union all select 'b', 211
union all select 'b', 303


select tb1.mc, tb1.s1 - tb2.s from @t1 tb1
inner join
(select mc, sum(s1) as s from @t2 group by mc) tb2
on tb1.mc = tb2.mc
愚人:喻世 引用 删除 m_r3326   /   2008-12-08 13:42:29
select 库存总量s1-sum(出库数量s1) from BBB,AAA where BBB.种类mc=AAA.种类mc group by BBB.种类mc,库存总量s1

结果: kind stock A 679 B 604
愚人:喻世 引用 删除 m_r3326   /   2008-12-08 13:30:05
SQL> select * from a;

MC           S1
---- ----------
A           997
B          1234

SQL> select * from b;

MC           S1
---- ----------
A           105
A           213
B           116
B           211
B           303

SQL> select a.mc,a.s1-b.q_out from a,(select mc,sum(s1) as q_out from b group by
mc)b where a.mc=b.mc;

MC   A.S1-B.Q_OUT
---- ------------
A             679
B             604
 

评分:0

我来说两句

日历

« 2024-04-11  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 9641
  • 日志数: 12
  • 建立时间: 2008-11-27
  • 更新时间: 2009-08-21

RSS订阅

Open Toolbar