多表数据量查询

自己是用的oralce,自己查了下mysql应该也是有的,其他需要自己验证

1.前端时间遇到一个查询需求:从四张表中分别查询:  年数据量和月数据量,然后通过统计图进行展示

2.第一次写的时候,没有想到好的方法去进行关联,因此采用了笨重的8次查询,虽然结果出来了,但显得很笨重,并且严重影响了首页的加载速度。

废话不多说直接上代码

主要 框架就是  select   ( selet  参数 from 表  where 条件)别名, 

                                             ( selet  参数 from 表  where 条件)别名,

                                             ( selet  参数 from 表  where 条件)别名

                                  from dual

select
        (select count(参数) from 表1 where to_char(SLSj ,'yyyy-MM') = to_char(sysdate,'yyyy-MM')) 别名1,
        (select count(参数) from 表2 where to_char(SLSj ,'yyyy-MM') = to_char(sysdate,'yyyy-MM')) 别名2,
        (select count(参数) from 表3 where to_char(SLRQ ,'yyyy-MM') = to_char(sysdate,'yyyy-MM')) 别名3,
        (select count(参数) from 表4 where to_char(SLSj ,'yyyy-MM') = to_char(sysdate,'yyyy-MM')) 别名4,
        (select count(参数) from 表1 where to_char(SLSj ,'yyyy') = to_char(sysdate,'yyyy')) 别名5,
        (select count(参数) from 表2 where to_char(SLSj ,'yyyy') = to_char(sysdate,'yyyy')) 别名6,
        (select count(参数) from 表3 where to_char(SLRQ ,'yyyy') = to_char(sysdate,'yyyy')) 别名7,
        (select count(参数) from 表4 where to_char(SLSj ,'yyyy') = to_char(sysdate,'yyyy'))别名8

 from dual

3.其中当时查询年数据的时候也稍微查了下,感觉这个方法挺好用的记录一下,可以方便年数据量、月数据量、日数据量的查询

select count(参数) from 表1 where to_char(对应sql的参数 ,'yyyy-MM') = to_char(sysdate,'yyyy-MM')) 别名

sysdate  函数直接用

4.欢迎大家交流

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值