该SQL如何写(100分)

  • 主题发起人 主题发起人 unicom
  • 开始时间 开始时间
U

unicom

Unregistered / Unconfirmed
GUEST, unregistred user!
表一
name value date
aaa
aab
aac
表二
name value date
aad
aae
aaf
aag
要求计算(aaa+aab+aac+aad+aae+aaf+aag)在指定DATE段内value的平均值
 
select Avg(value) from
(select * from 表一
where date <:date1 and date >: date2
union all
select * from 表二
where date <:date1 and date >: date2)
 
select avg(a.value) from ((select * from 表一) union (select * from 表二)) a
where a.name in (select b.name from ((select * from 表一) union (select * from 表二)) b where b.date between DateStart and DateEnd)
 
select Avg(value) from
(select * from 表一
where date <:date1 and date >: date2
union all
select * from 表二
where date <:date1 and date >: date2)
 
我用的是ACCESS,是不是不支持UNION
报FROM子句错
 
用aceess怕不支持sql
干脆用第三张表啊,把两张表的记录合起来,再求平均值
 
select avg(3*value+4*value) as newvalue
from 表一,表二
where 表一.name like aa* and 表二.name like aa*
and date>:datestart and date<:dateend
newvalue即为你所求的
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部