zoukankan      html  css  js  c++  java
  • MYSQL CASE WHEN THEN END 用法

    SELECT qr_cash_record.*,
    CASE
    WHEN cashrecord_type = 3 THEN
    (SELECT product_title FROM qr_fundsupport LEFT JOIN qr_fundplan
    ON fundplan_id = fundsupport_ref_fundplanid LEFT JOIN qr_product
    ON product_id = fundplan_ref_productid WHERE fundsupport_id = cashrecord_ref_id )
    WHEN cashrecord_type = 4 THEN
    (SELECT product_title FROM qr_fundplan
    LEFT JOIN qr_product
    ON product_id = fundplan_ref_productid
    WHERE fundplan_id = cashrecord_ref_id )
    ELSE
    (SELECT product_title FROM qr_touristorder
    LEFT JOIN qr_product ON product_id = touristorder_ref_productid
    WHERE touristorder_id = cashrecord_ref_id )
    END AS product_title,

    CASE
    WHEN cashrecord_type = 3 THEN
    (SELECT product_id FROM qr_fundsupport LEFT JOIN qr_fundplan
    ON fundplan_id = fundsupport_ref_fundplanid LEFT JOIN qr_product
    ON product_id = fundplan_ref_productid WHERE fundsupport_id = cashrecord_ref_id )
    WHEN cashrecord_type = 4 THEN
    (SELECT product_id FROM qr_fundplan
    LEFT JOIN qr_product
    ON product_id = fundplan_ref_productid
    WHERE fundplan_id = cashrecord_ref_id )
    ELSE
    (SELECT product_id FROM qr_touristorder
    LEFT JOIN qr_product ON product_id = touristorder_ref_productid
    WHERE touristorder_id = cashrecord_ref_id )
    END AS product_id,
    CASE
    WHEN cashrecord_type = 3 THEN
    (SELECT product_type FROM qr_fundsupport LEFT JOIN qr_fundplan
    ON fundplan_id = fundsupport_ref_fundplanid LEFT JOIN qr_product
    ON product_id = fundplan_ref_productid WHERE fundsupport_id = cashrecord_ref_id )
    WHEN cashrecord_type = 4 THEN
    (SELECT product_type FROM qr_fundplan
    LEFT JOIN qr_product
    ON product_id = fundplan_ref_productid
    WHERE fundplan_id = cashrecord_ref_id )
    ELSE
    (SELECT product_type FROM qr_touristorder
    LEFT JOIN qr_product ON product_id = touristorder_ref_productid
    WHERE touristorder_id = cashrecord_ref_id )
    END AS product_type,

    CASE
    WHEN cashrecord_type = 3 THEN
    (SELECT fundplan_ref_userid FROM qr_fundsupport LEFT JOIN qr_fundplan
    ON fundplan_id = fundsupport_ref_fundplanid
    WHERE fundsupport_id = cashrecord_ref_id )
    WHEN cashrecord_type = 4 THEN
    (SELECT fundplan_ref_userid FROM qr_fundplan
    WHERE fundplan_id = cashrecord_ref_id )
    ELSE
    (SELECT touristorder_ref_grideorderid FROM qr_touristorder
    WHERE touristorder_id = cashrecord_ref_id )
    END AS ref_user_id,

    CASE
    WHEN cashrecord_type = 3 THEN
    (SELECT auth_realname FROM qr_fundsupport LEFT JOIN qr_fundplan
    ON fundplan_id = fundsupport_ref_fundplanid
    LEFT JOIN qr_userauth ON auth_ref_userid = fundplan_ref_userid
    WHERE fundsupport_id = cashrecord_ref_id AND auth_type=0 AND auth_limitstate=2 )
    WHEN cashrecord_type = 4 THEN
    (SELECT auth_realname FROM qr_fundplan
    LEFT JOIN qr_userauth ON auth_ref_userid = fundplan_ref_userid
    WHERE fundplan_id = cashrecord_ref_id AND auth_type=0 AND auth_limitstate=2 )
    ELSE
    (SELECT auth_realname FROM qr_touristorder
    LEFT JOIN qr_userauth ON auth_ref_userid = touristorder_ref_grideorderid
    WHERE touristorder_id = cashrecord_ref_id AND auth_type=0 AND auth_limitstate=2 )
    END AS ref_user_realname

    FROM qr_cash_record;

  • 相关阅读:
    BootStrap .row-cols 类的用法
    苹果手机浏览器$(document).on(“click”,function(){})点击无效的问题
    $("节点名").html("字符串")和$("节点名").text("字符串")区别
    linux 安装Nginx
    linux安装nginx
    vue dev开发环境跨域和build生产环境跨域问题解决
    正在载入中......loading页面的几种方法
    浏览器断点调试js
    vue组件之间传值方式解析
    基于Vue + Vuex + Vue-router + Webpack 2.0打造微信界面
  • 原文地址:https://www.cnblogs.com/morpheusliu/p/6138466.html
Copyright © 2011-2022 走看看