zoukankan      html  css  js  c++  java
  • case用法

    SELECT
    id,
    service_id,
    order_sn,
    yuyue_date,
    yuyue_time,
    (
    CASE
    WHEN ( yuyue_date != '' && yuyue_time != '' ) THEN
    UNIX_TIMESTAMP( CONCAT( yuyue_date, ' ', yuyue_time ) )
    WHEN ( yuyue_date = '' && yuyue_time != '' ) THEN
    addtime
    WHEN ( yuyue_date = '' && yuyue_time = '' ) THEN
    0
    END
    ) AS yuyue_finnal
    FROM
    `order_info`
    WHERE
    token = '7673d6eb1ec6122c'
    AND uid = 5789729
    AND (
    CASE
    WHEN ( yuyue_date != '' && yuyue_time != '' ) THEN
    UNIX_TIMESTAMP( CONCAT( yuyue_date, ' ', yuyue_time ) )
    WHEN ( yuyue_date = '' && yuyue_time != '' ) THEN
    addtime
    WHEN ( yuyue_date = '' && yuyue_time = '' ) THEN
    0
    END
    ) BETWEEN 1611072000
    AND 1611504000

    --------------------------------------------------------------

    SELECT
    sum(case when x.have_renew = 1 then 1 else 0 end) AS 未续费未到期,
    sum(case when x.have_renew = 2 then 1 else 0 end) AS 已续费未到期,
    sum(case when x.have_renew = 3 then 1 else 0 end) AS 曾经续费已到期,
    sum(case when x.have_renew = 4 then 1 else 0 end) AS 未续费已到期
    FROM
    (SELECT
    MAX(end_time) AS end_time,

    CASE
    WHEN (COUNT(id) > 1 && MAX(end_time) > 1608277794) THEN 1
    WHEN (COUNT(id) = 1 && MAX(end_time) > 1608277794) THEN 2
    WHEN (COUNT(id) > 1 && MAX(end_time) < 1608277794) THEN 3
    WHEN (COUNT(id) = 1 && MAX(end_time) < 1608277794) THEN 4
    END
    AS have_renew
    FROM
    addons_pay
    WHERE
    module = 'Shop'
    AND pay_type != 3
    GROUP BY
    public_id) as x

  • 相关阅读:
    网站性能之meta标签
    布局中的css要素
    MVC中配置OutputCache的VaryByParam参数无效的问题
    C# 4.0 类与继承
    想要充值手机话费吗???亿矿网找错误送话费啦
    .Net Core 依赖注入
    Hadoop实战内容摘记
    Thead,TheadPool,Task,async,await 的前世今生
    VS Code 中 使用 Git版本控制工具
    dotnet 命令大全-理论版
  • 原文地址:https://www.cnblogs.com/wangshuazi/p/14314059.html
Copyright © 2011-2022 走看看