读书人

依照列查询不同数据

发布时间: 2013-08-09 15:16:24 作者: rapoo

按照列查询不同数据

1,业务说明:

报表查询数据,第一列要查询A类型数据,第二列要查询B类型数据(如A1.jpg)

日期温度入库量出库量2013/7/31冷藏2001002013/7/30冷冻13020

2,sql:

SELECT 日期, 类型, 温度, 数量, company  from ((select trunc(a.estimate_date, 'dd') as 日期,                a.name as 类型,                a.category as 温度,                sum(a.moved_quantity_bu) as 数量,                a.company_id as company           from A a          group by trunc(a.estimate_date, 'dd'),                   a.name,                   a.category,                   a.company_id) union all        (select trunc(b.intend_ship_date, 'dd') as 日期,                '出库单' as 类型,                b.category as 温度,                sum(b.shipped_quantity_bu) as 数量,                b.company_id as company           from B b          group by trunc(b.intend_ship_date, 'dd'), b.category, b.company_id)) WHERE trunc(日期, 'dd') >= ?   and trunc(日期, 'dd') <= ?   and company = ? ORDER BY 日期, 温度

?3,报表实现:

日期温度入库数量出库数量=ds1.group(日期)=ds1.group(温度)=ds1.select1(数量,类型=='收货单')=ds1.select1(数量,类型=='出库单')

?

?

读书人网 >开源软件

热点推荐