我需要类似的东西:
选择平均值(选择不同的...) 从...
但它不起作用
来自评论:
select avg( select distinct x.money
from departmentx x inner join
departmenty y
on x.identity = y.identity
union
select distinct y.money
from departmentx x inner join
departmenty y
on x.identity = y.identity
where money not null
)
from department
答案 0 :(得分:1)
以下可能是您编写的代码的意图:
select avg(money)
from (select distinct x.money
from departmentx x inner join
departmenty y
on x.identity = y.identity
union
select distinct y.money
from departmentx x inner join
departmenty y
on x.identity = y.identity
where money is not null
) m
我离开了“古怪主义”:
distinct
。 union
负责照顾。money is not null
。 avg()
忽略NULL
。money
,因为这是内置类型的名称。