Paradox表的SQL语句书写问题(80分)

  • 主题发起人 主题发起人 苯苯
  • 开始时间 开始时间

苯苯

Unregistered / Unconfirmed
GUEST, unregistred user!
现在有两个表:
branch.db
arae char(4)
branchname char(20)

oper.db
area char(4)
total numberic
delay numberic
userid char(8)

假设branch.db的数据为:
X X_name
Z01 Z01_name
Z02 Z02_name
M M_name

oper.db为操作情况表假设有如下的数据
oper.db
area total delay userid
-----------------------------
X 100.0 2.3 abcd
X 50.6 0 abcd
Z01 200.9 3.5 abcd
Z01 300 5 abcd
Z01 130.0 3 Eric
Z02 140.8 10.4 Eric
Z02 140.8 10.4 abcd
Z02 250.0 30.5 Eric

得到的结果为:userid='abcd'的统计数据:即为:
X_name 150.6 2.3
Z01_name 500.9 8.5
Z02_name 140.8 10.4

请问SQL语句怎么写?
 
select branch.branchname sum(oper.total),sum(oper.delay)
from oper,branch
where oper.userid='abcd' and oper.arer=branch.arer
 
小猪的有问题??
 
SELECT branch.branchname,sum(oper.totle),sum(oper.delay)
FROM branch,oper
WHERE oper.userid="abcd" AND branch.area=oper.area
GROUP BY branch.branchname

如果不行,问题可能出在delay字段上。
 
SELECT branch.branchname sum(oper.totle),sum(oper.delay)
FROM branch
WHERE area in ( SELECT area FROM oper WHERE userid="abcd" )
GROUP BY branch.branchname

 
好象你们给的答案全都不正确哦!!

to Jacer为什么会出现在字段delay上???
To 小猪:你的方法肯定不符合要求的。
 
SELECT branch.branchname,sum(oper.total) as tl,sum(oper.delay_fee) as dl
FROM "branch.db" branch,"oper.db" oper
WHERE oper.userid='abcd' and oper.area=branch.area
GROUP BY oper.area,branch.branchname
 
猜测试没有设置索引,主键等原因。正试
 
接受答案了.
 
如果没有设置索引,主键,就要:
select a.branchname,sum(b.total),sum(b.delay)
from a,b
where b.userid='abcd' and b.area=a.area
group by b.area,a.branchname
----a:branch, b:oper
按照你的数据测试成功。(嘻嘻,和zengr 的怎么一样呢?)
如果你增加了别的字段作为主键,这个sql 语言会写的更简洁的.
 
后退
顶部