zoukankan      html  css  js  c++  java
  • oracle_多字段统计(多count)

    oracle_多字段统计

    查询同一张表中同一字段的不同值的综合,方法如下:

    select o.code 礼品代码,
    o.name 礼品名称,
    l.couponactivityid 券活动定义,
    count(l.couponno) as 券总数量,
    count(case
    when l.state in ('0') then
    '0'
    end) 未兑换券数量,
    count(case
    when l.state in ('1') then
    '1'
    end) 已兑换未核销券数量,
    count(case
    when l.state in ('2') then
    '2'
    end) 已核销券数量
    from css_coupon l, css_award o
    where l.couponactivityid = o.couponcode
    and o.state = '正常'
    group by o.code, o.name, l.couponactivityid

    用法解析:

    count(case
    when l.state in ('0') then
    '0'
    end) 未兑换券数量,
    count(case
    when l.state in ('1') then
    '1'
    end) 已兑换未核销券数量,
    count(case
    when l.state in ('2') then
    '2'
    end) 已核销券数量

    上述中有三个count,分别查询同一个字段l.state ,但是对这一个字段的查询值是不同的,即 in ('0') in ('1') in ('2')  算法等同于,='0' ='1' ='2'  

    此处简单记录一下,有兴趣的话可以搜索一下case的用法

  • 相关阅读:
    Placing Rooks-CF 1342E
    Yet Another Counting Problem-CF 1342C
    [SDOI2016]齿轮
    Rinne Loves Xor
    Labyrinth CodeForces
    Nastya and Scoreboard
    Teacher Bo HDU
    Blood Cousins Return
    D Tree HDU
    设计模式学习笔记(八、行为型-策略模式)
  • 原文地址:https://www.cnblogs.com/Sir-Li/p/4057243.html
Copyright © 2011-2022 走看看