zoukankan      html  css  js  c++  java
  • 数据库多行转一行

     SELECT  max(case sys_date when '20181019' then amount end) as trade_settle_amount0, max(case sys_date when '20181019' then number end) as trade_settle_number0, max(case sys_date when '20181018' then amount end) as trade_settle_amount1,  max(case sys_date when '20181018' then number end) as trade_settle_number1, max(case sys_date when '20181017' then amount end) as trade_settle_amount2,  max(case sys_date when '20181017' then number end) as trade_settle_number2, max(case sys_date when '20181016' then amount end) as trade_settle_amount3,  max(case sys_date when '20181016' then number end) as trade_settle_number3, max(case sys_date when '20181015' then amount end) as trade_settle_amount4,  max(case sys_date when '20181015' then number end) as trade_settle_number4, max(case sys_date when '20181014' then amount end) as trade_settle_amount5,  max(case sys_date when '20181014' then number end) as trade_settle_number5, max(case sys_date when '20181013' then amount end) as trade_settle_amount6,  max(case sys_date when '20181013' then number end) as trade_settle_number6, max(case sys_date when 'total' then amount end) as trade_settle_amount7,  max(case sys_date when 'total' then number end) as trade_settle_number7  from  (SELECT sys_date,sum(trans_amount) as amount,count(1) as number from trade_log where mer_id = '880001'  AND trade_trans_state = 'S'  and sys_date>='20181013' and sys_date<='20181019'  GROUP BY sys_date  UNION ALL SELECT 'total' , sum(amount), sum(number)  from( SELECT sum(trans_amount) as amount,count(1) as number from trade_log where mer_id = '880001'  AND trade_trans_state = 'S'  and sys_date>='20181013' and sys_date<='20181019'))

  • 相关阅读:
    基于properties文件的Spring Boot多环境切换
    在mysql命令行下执行sql文件
    thymeleaf th:href 多个参数传递格式
    Mybatis 级联查询时只查出了一条数据
    IDEA技巧-自动导包(Auto import)以及自动优化包
    Drools学习教程
    Drools学习教程
    Drools学习教程
    Drools学习教程
    一道有趣的类加载面试题
  • 原文地址:https://www.cnblogs.com/chexiedaping/p/14155368.html
Copyright © 2011-2022 走看看