• 查询行转列


    SELECT to_date(to_char(last_day(add_months(SYSDATE, -2))+1,'yyyy-mm-dd'),'yyyy-mm-dd'),to_date(to_char(last_day(add_months(SYSDATE, -1)),'yyyy-mm-dd'),'yyyy-mm-dd')   FROM dual;
    SELECT to_date(to_char(last_day(add_months(SYSDATE, -3))+1,'yyyy-mm-dd'),'yyyy-mm-dd'),to_date(to_char(last_day(add_months(SYSDATE, -2)),'yyyy-mm-dd'),'yyyy-mm-dd')   FROM dual;
    SELECT to_date(to_char(last_day(add_months(SYSDATE, -4))+1,'yyyy-mm-dd'),'yyyy-mm-dd'),to_date(to_char(last_day(add_months(SYSDATE, -3)),'yyyy-mm-dd'),'yyyy-mm-dd')   FROM dual;

    1: select sum(case when to_char(billingdate,'yyyy-mm') =to_char(last_day(add_months(SYSDATE, 0)),'yyyy-mm') then quantity else 0 end) currentmonthquantity, 

              sum(case when to_char(billingdate,'yyyy-mm') =to_char(last_day(add_months(SYSDATE, -1)),'yyyy-mm') then quantity else 0 end) , 
              sum(case when to_char(billingdate,'yyyy-mm') =to_char(last_day(add_months(SYSDATE, -2)),'yyyy-mm') then quantity else 0 end), 
              sum(case when to_char(billingdate,'yyyy-mm') =to_char(last_day(add_months(SYSDATE, -3)),'yyyy-mm') then quantity else 0 end) , 
              prodid,branchid,sum(quantity) quantity From (
                 select * From tb_gos_sale_salestockoutdet
                 where billingdate between to_date(to_char(last_day(add_months(SYSDATE, -4))+1,'yyyy-mm-dd'),'yyyy-mm-dd') and sysdate
             ) group by prodid,branchid
             having prodid='SPH00013655' 

    2:   select * From (

       select to_char(billingdate,'yyyy-mm') billdate,prodid,branchid,sum(quantity) quantity From (
                 select * From tb_gos_sale_salestockoutdet
                 where billingdate between to_date(to_char(last_day(add_months(SYSDATE, -4))+1,'yyyy-mm-dd'),'yyyy-mm-dd') and sysdate
             ) group by to_char(billingdate,'yyyy-mm'),prodid,branchid
             having prodid='SPH00013655'
             )
              pivot 
              (
                 sum(quantity)
                 for billdate in ('2011-03' as 三月销售,'2011-04','2011-05','2011-06')
              )
              

  • 相关阅读:
    遍历一个枚举类型
    ASP.NET:C#中时间格式的转换
    DataAdapter去批量更新数据的FAQ
    .Net/C#: 实现支持断点续传多线程下载的 Http Web 客户端工具类 (第2版) (C# DIY HttpWebClient) 收藏
    如何使数据库中取出的数据保持原有格式
    如何获取控制台应用程序自己的文件名
    2008将倒掉一大部分的工厂和贸易公司
    组六对半分组组合投资方案(36789)
    重又归孑然一身
    善于总结
  • 原文地址:https://www.cnblogs.com/pan11jing/p/2065568.html
Copyright © 2020-2023  润新知