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

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

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

一道数据库笔试题目


_|9Y'[t051Testing软件测试网1s*zE1}h&D m
有两个表51Testing软件测试网MH-N0zOx6YY
51Testing软件测试网-XnDZa[
表一 AAA51Testing软件测试网C'T(M!O'mGE$U k
种类mc        库存总量s151Testing软件测试网]'}W1`WDWR
A        997       
Nt9It@] P,z9q q0B        1234
v6Ws,`} V+g0
Nhfj zyF Q0表二         BBB
:t#J$P({/b*_2N0种类mc        出库数量s1
;M}pNK5irR8Iu0A        105
m_'F!CX8V"s+S0I0A        213
W(@"Xa J E xZ0B        11651Testing软件测试网0^-Z BSs(G@/F
B        21151Testing软件测试网Gx S-HT4oo
B        303
(@)X9cLO5Tf+P9dq0用一条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-27  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

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

RSS订阅

Open Toolbar