美文网首页
Postgress-在集合查询及合并多次查询结果

Postgress-在集合查询及合并多次查询结果

作者: WXL_JIANSHU | 来源:发表于2020-12-07 14:08 被阅读0次

    0、知识点

    with
    union
    

    1、代码

    
    (with dataA as (select status,storage_time,cargo_cn,* from (select * from sp_base_waybill
    where cargo_cn  like ('%毛肚%')
    or  cargo_cn    like ('%黄喉%')
    or  cargo_cn   like ('%肠%')
    or  cargo_cn   like ('%鸭血%')
    or  cargo_cn   like ('%生牛肉%')
    or  cargo_cn   like ('%生鸡肉%')
    or  cargo_cn   like ('%生猪肉%')
    or  cargo_cn   like ('%鱼%')
    or  cargo_cn   like ('%虾%')
    or  cargo_cn   like ('%蟹%')
        order by storage_time desc
        ) as aaa where   cargo_cn  not like('%熟%') and status>5
                                          and storage_time  between  '2020-11-23 00:00:00' and   '2020-11-30 00:00:00')
    select '11月23日-11月29日 模糊'as 查询范围, sum(dataA.receivecargo_weight) from dataA)
    union all
    (with dataB AS (select status,storage_time,cargo_cn,* from (select * from sp_base_waybill
    where cargo_cn  like ('%毛肚%')
    or  cargo_cn    like ('%黄喉%')
    or  cargo_cn   like ('%肠%')
    or  cargo_cn   like ('%鸭血%')
    or  cargo_cn   like ('%生牛肉%')
    or  cargo_cn   like ('%生鸡肉%')
    or  cargo_cn   like ('%生猪肉%')
    or  cargo_cn   like ('%鱼%')
    or  cargo_cn   like ('%虾%')
    or  cargo_cn   like ('%蟹%')
        order by storage_time desc
        ) as aaa where   cargo_cn  not like('%熟%') and status>5
                                          and storage_time  between  '2020-11-30 00:00:00' and   '2020-12-07 00:00:00')
    select '11月30日-12月6日 模糊' as 查询范围, sum(dataB.receivecargo_weight)  from   dataB);
    

    2、效果

    image.png

    相关文章

      网友评论

          本文标题:Postgress-在集合查询及合并多次查询结果

          本文链接:https://www.haomeiwen.com/subject/mnttgktx.html