SQL横向添加

select t.customer, count(t.customer)
  from tablea t
 where t.phoneno in ('777777', '222222')
 group by t.customer order by t.customer;
 
 
 select t.customer, count(t.customer)
  from tablea t
 where t.phoneno = '777777'
 group by t.customer order by t.customer;
 
 select t.customer, count(t.customer)
  from tablea t
 where t.phoneno = '222222'
 group by t.customer order by t.customer;
 
 
 
select C.*,nvl(D.count_2,0)
  from (select A.customer, A.count, B.count_7
          from (select t.customer, count(t.customer) as count
                  from tablea t
                 where t.phoneno in ('777777', '222222')
                 group by t.customer
                 order by t.customer) A
          left join (select t.customer, count(t.customer) as count_7
                      from tablea t
                     where t.phoneno = '777777'
                     group by t.customer
                     order by t.customer) B on A.customer = B.customer) C
  left join (select t.customer, count(t.customer) as count_2
               from tablea t
              where t.phoneno = '222222'
              group by t.customer
              order by t.customer) D on C.customer = D.customer

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MongoDB和SQL是两种不同类型的数据库管理系统,它们在数据存储和查询方面有一些区别。 1. 数据模型:MongoDB是一种文档数据库,它使用类似JSON的BSON(二进制JSON)格式来存储数据。每个文档可以具有不同的结构,这使得MongoDB非常灵活。而SQL是基于表的关系数据库,数据以表格形式存储,每个表都有固定的列和行。 2. 查询语言:MongoDB使用一种称为MongoDB查询语言(MQL)的语言来进行查询,它与JavaScript语法相似。MQL支持丰富的查询操作符和聚合功能。SQL使用结构化查询语言(SQL)进行查询,它是一种通用的查询语言,用于处理关系型数据。 3. 扩展性:MongoDB具有良好的横向扩展性,可以轻松地在多个服务器之间分布数据。而SQL数据库通常以垂直方式扩展,通过在单个服务器上增加硬件资源来提高性能。 4. 事务支持:SQL数据库通常支持事务处理,可以保证数据的一致性和完整性。而MongoDB在早期版本中缺乏对事务的完全支持,但在最近的版本中已经添加了对多文档事务的支持。 5. 数据关系:SQL数据库使用外键来建立数据之间的关系,这使得在查询和连接多个表时更加方便。MongoDB没有内置的外键概念,但可以通过嵌入文档或手动引用文档来建立关系。 总的来说,MongoDB适用于需要灵活数据模型和大规模横向扩展的场景,而SQL数据库适用于需要严格结构化数据和事务支持的场景。选择哪种数据库取决于具体的业务需求和数据特点。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值