将行数据转到列显示的sql例子
2010-06-18 13:02
218 查看
select
a.forecast_year "提报年",
a.forecast_cycle_number "提报周",
c.PRODUCT_LINE_NAME "产品线",
b.product_code "产品编码",
b.product_sname "产品名称",
max(decode(b.forecast_ver,-1,b.PARAMETER_1)) "T-1周销量" ,
max(decode(b.forecast_ver,-1,b.PARAMETER_2)) "T-1周上推5周平均销量" ,
max(decode(b.forecast_ver,-1,b.FORECAST_REF_FINAL_STOCK)) "T-1周期末库存" ,
max(decode(b.forecast_ver,-1,b.PARAMETER_10)) "T-1周库存周转天数" ,
max(decode(b.forecast_ver,0,b.FORECAST_REF_PLAN_ARRIVE)) "T周确认到货" ,
max(decode(b.forecast_ver,0,b.forecast_retail_input)) "T周零售预测" ,
max(decode(b.forecast_ver,0,b.FORECAST_REF_FINAL_STOCK)) "T周期末库存" ,
max(decode(b.forecast_ver,0,b.PARAMETER_10)) "T周库存周转天数" ,
max(decode(b.forecast_ver,1,b.FORECAST_REF_PLAN_ARRIVE)) "T+1周确认到货" ,
max(decode(b.forecast_ver,1,b.forecast_retail_input)) "T+1周零售预测" ,
max(decode(b.forecast_ver,1,b.FORECAST_REF_FINAL_STOCK)) "T+1周期末库存" ,
max(decode(b.forecast_ver,1,b.PARAMETER_10)) "T+1周库存周转天数" ,
max(decode(b.forecast_ver,2,b.PARAMETER_11)) "T+2周评审后预测" ,
max(decode(b.forecast_ver,2,b.forecast_retail_input)) "T+2周零售预测" ,
max(decode(b.forecast_ver,2,b.FORECAST_REF_FINAL_STOCK)) "T+2周期末库存" ,
max(decode(b.forecast_ver,2,b.PARAMETER_10)) "T+2周库存周转天数" ,
max(decode(b.forecast_ver,3,b.FORECAST_REF_PLAN)) "T+3周计划数" ,
max(decode(b.forecast_ver,3,b.forecast_demand_input)) "T+3周需求预测" ,
max(decode(b.forecast_ver,3,b.forecast_retail_input)) "T+3周零售预测" ,
max(decode(b.forecast_ver,3,b.FORECAST_REF_FINAL_STOCK)) "T+3周期末库存" ,
max(decode(b.forecast_ver,3,b.PARAMETER_10)) "T+3周库存周转天数" ,
max(decode(b.forecast_ver,3,b.PARAMETER_12)) "T+3周周转天数下限" ,
max(decode(b.forecast_ver,3,b.PARAMETER_13)) "T+3周周转天数上限" ,
max(decode(b.forecast_ver,4,b.FORECAST_REF_PLAN)) "T+4周计划数" ,
max(decode(b.forecast_ver,4,b.forecast_demand_input)) "T+4周需求预测" ,
max(decode(b.forecast_ver,4,b.forecast_retail_input)) "T+4周零售预测" ,
max(decode(b.forecast_ver,5,b.FORECAST_REF_PLAN)) "T+5周计划数" ,
max(decode(b.forecast_ver,5,b.forecast_demand_input)) "T+5周需求预测" ,
max(decode(b.forecast_ver,5,b.forecast_retail_input)) "T+5周零售预测" ,
max(decode(b.forecast_ver,6,b.FORECAST_REF_PLAN)) "T+6周计划数" ,
max(decode(b.forecast_ver,6,b.forecast_demand_input)) "T+6周需求预测" ,
max(decode(b.forecast_ver,6,b.forecast_retail_input)) "T+6周零售预测"
from ecc_fst.forecast_collect_title a,
ecc_fst.forecast_collect_DETAIL b,
ecc_fnd.product_line_v c
where a.forecast_collect_title_id = b.forecast_collect_title_id
and a.forecast_year = 2010
and a.forecast_cycle_number=24
and a.product_line_id = c.PRODUCT_ID
and a.fst_role_lookup_code='PR'
and a.fact_submit_customer_code = 'B0004854'
and b.forecast_ver>=-1
group by
a.forecast_collect_title_id,
a.forecast_year,
a.forecast_cycle_number,
c.PRODUCT_LINE_NAME,
b.product_code,
b.product_sname
order by a.forecast_collect_title_id,b.product_code
a.forecast_year "提报年",
a.forecast_cycle_number "提报周",
c.PRODUCT_LINE_NAME "产品线",
b.product_code "产品编码",
b.product_sname "产品名称",
max(decode(b.forecast_ver,-1,b.PARAMETER_1)) "T-1周销量" ,
max(decode(b.forecast_ver,-1,b.PARAMETER_2)) "T-1周上推5周平均销量" ,
max(decode(b.forecast_ver,-1,b.FORECAST_REF_FINAL_STOCK)) "T-1周期末库存" ,
max(decode(b.forecast_ver,-1,b.PARAMETER_10)) "T-1周库存周转天数" ,
max(decode(b.forecast_ver,0,b.FORECAST_REF_PLAN_ARRIVE)) "T周确认到货" ,
max(decode(b.forecast_ver,0,b.forecast_retail_input)) "T周零售预测" ,
max(decode(b.forecast_ver,0,b.FORECAST_REF_FINAL_STOCK)) "T周期末库存" ,
max(decode(b.forecast_ver,0,b.PARAMETER_10)) "T周库存周转天数" ,
max(decode(b.forecast_ver,1,b.FORECAST_REF_PLAN_ARRIVE)) "T+1周确认到货" ,
max(decode(b.forecast_ver,1,b.forecast_retail_input)) "T+1周零售预测" ,
max(decode(b.forecast_ver,1,b.FORECAST_REF_FINAL_STOCK)) "T+1周期末库存" ,
max(decode(b.forecast_ver,1,b.PARAMETER_10)) "T+1周库存周转天数" ,
max(decode(b.forecast_ver,2,b.PARAMETER_11)) "T+2周评审后预测" ,
max(decode(b.forecast_ver,2,b.forecast_retail_input)) "T+2周零售预测" ,
max(decode(b.forecast_ver,2,b.FORECAST_REF_FINAL_STOCK)) "T+2周期末库存" ,
max(decode(b.forecast_ver,2,b.PARAMETER_10)) "T+2周库存周转天数" ,
max(decode(b.forecast_ver,3,b.FORECAST_REF_PLAN)) "T+3周计划数" ,
max(decode(b.forecast_ver,3,b.forecast_demand_input)) "T+3周需求预测" ,
max(decode(b.forecast_ver,3,b.forecast_retail_input)) "T+3周零售预测" ,
max(decode(b.forecast_ver,3,b.FORECAST_REF_FINAL_STOCK)) "T+3周期末库存" ,
max(decode(b.forecast_ver,3,b.PARAMETER_10)) "T+3周库存周转天数" ,
max(decode(b.forecast_ver,3,b.PARAMETER_12)) "T+3周周转天数下限" ,
max(decode(b.forecast_ver,3,b.PARAMETER_13)) "T+3周周转天数上限" ,
max(decode(b.forecast_ver,4,b.FORECAST_REF_PLAN)) "T+4周计划数" ,
max(decode(b.forecast_ver,4,b.forecast_demand_input)) "T+4周需求预测" ,
max(decode(b.forecast_ver,4,b.forecast_retail_input)) "T+4周零售预测" ,
max(decode(b.forecast_ver,5,b.FORECAST_REF_PLAN)) "T+5周计划数" ,
max(decode(b.forecast_ver,5,b.forecast_demand_input)) "T+5周需求预测" ,
max(decode(b.forecast_ver,5,b.forecast_retail_input)) "T+5周零售预测" ,
max(decode(b.forecast_ver,6,b.FORECAST_REF_PLAN)) "T+6周计划数" ,
max(decode(b.forecast_ver,6,b.forecast_demand_input)) "T+6周需求预测" ,
max(decode(b.forecast_ver,6,b.forecast_retail_input)) "T+6周零售预测"
from ecc_fst.forecast_collect_title a,
ecc_fst.forecast_collect_DETAIL b,
ecc_fnd.product_line_v c
where a.forecast_collect_title_id = b.forecast_collect_title_id
and a.forecast_year = 2010
and a.forecast_cycle_number=24
and a.product_line_id = c.PRODUCT_ID
and a.fst_role_lookup_code='PR'
and a.fact_submit_customer_code = 'B0004854'
and b.forecast_ver>=-1
group by
a.forecast_collect_title_id,
a.forecast_year,
a.forecast_cycle_number,
c.PRODUCT_LINE_NAME,
b.product_code,
b.product_sname
order by a.forecast_collect_title_id,b.product_code
相关文章推荐
- mysql导入导出数据中文乱码解决方法小结(1、navicat导入问题已解决,创建连接后修改连接属性,选择高级->将使用Mysql字符集复选框去掉,下拉框选择GBK->导入sql文件OK;2、phpmyadmin显示乱码的问题也解决,两步:1.将sql文件以utf8的字符集编码另存,2.将文件中sql语句中的字段字符集编码改成utf8,导入OK)
- mysql 如何用一条SQL将一张表里的数据插入到另一张表 3个例子
- SQL语句增加虚拟字段,并根据情况显示不同的数据。。。(已阅。。。未阅。。)
- ArrayList利用迭代器Iterator遍历方法实现数据(新闻)的删除、添加、显示功能例子
- T-SQL 合并多行数据显示到一行
- sqlplus查询数据时,显示乱码的解决办法
- 利用GridView显示主细表并一次编辑明细表所有数据的例子
- 关于VS2005中C#代码用F12转到定义时,总是显示从元数据的问题?
- 解决pl/sql 查询数据中文显示成?
- sql 数据显示的顺序,要根据WHERE中输入的条件顺序来显示
- DevExpress中的ASPxGridView显示Sql中数据方法
- asp.net 中 sql dataset 显示数据
- Oracle多行数据合并一行显示【SQL实现详细解析】
- oracle12c JSON数据 使用SQL语句实现多表左外连接 显示无效数据 分页查询
- PL/SQL 查询和显示的数据 中文乱码
- JavaScript语言显示XML数据的简单例子
- Flex中如何将XML数据显示在DataGrid控件中的例子
- sql将几张表的数据合并到一张表里面一行显示
- SQL,纵向数据变为横向显示。
- 经典SQL语句,可以让行的数据当列来显示