首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对包含聚合或子查询的表达式执行聚合函数

对包含聚合或子查询的表达式执行聚合函数
EN

Stack Overflow用户
提问于 2017-01-17 19:54:08
回答 1查看 39关注 0票数 0

不能执行任何类型的聚合函数。我有2个表与实体和一个表,其中包含每个实体的事务。

代码语言:javascript
复制
#qui
        +--------+------------+
        |  idx   | nbn        |
        +--------+------------+
        | 44444  | 152357     |    
        | 55555  | 778852     |
        | 66666  | 776856     |
        +--------+------------+
#zea
        +--------+------------+
        |  idx   | nbn        |
        +--------+------------+
        | 11111  | 159357     |    
        | 22222  | 753852     |
        | 33333  | 745856     |
        +--------+------------+
#trx
        +--------+------------+---------+--------+
        |  idx   | nbn        |trx_amt  |date    |
        +--------+------------+---------+--------+
        | 11111  | 159357     |100      |01-01-16|
        | 22222  | 753852     |200      |04-04-16|
        | 33333  | 745856     |300      |11-05-16|
        +--------+------------+---------+--------+

我的问题是:

代码语言:javascript
复制
    select 
      date
     ,qui_co = count (case when trx.idx in (select idx from qui) then trx_amt
     ,zea_co = count (case when trx.idx in (select idx from zea) then trx_amt 
end)
    from 
      trx 
        inner join (select idx from qui
                    union 
                    select idx from zea) xxx
        on trx.idx = xxx.idx
group by date

对其他解决方案有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2017-01-17 20:03:44

您应该能够使用left joins做到这一点:

代码语言:javascript
复制
select [date], count(q.idx), count(z.idx)
from trx t
left join qui q on t.idx=q.idx
left join zea z on t.idx=z.idx
group by [date]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41696440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档