博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
超强的sql语句
阅读量:6922 次
发布时间:2019-06-27

本文共 5149 字,大约阅读时间需要 17 分钟。

select row.*, rownum rownum

from (select partyId,

partyName,           partyCode,           sum(orderNum) as orderNum,           sum(orderAmount) as orderAmount      from (select pp.id as partyId,                   pp.name as partyName,                   pp.code as partyCode,                   count(tso.id) as orderNum,                   "SUM"(case                           when tsoh.order_type = 10 then                            (TSO.UNIT_PRICE * TSO.FINAL_QUANTITY -                            (tso.FINAL_QUANTITY / tso.ORDERING_QUANTITY) *                            (TSO.COUPON + TSO.DISCOUNT_FEE))                           ELSE                            (-TSO.unit_price * tso.FINAL_QUANTITY +                            (tso.FINAL_QUANTITY / tso.ORDERING_QUANTITY) *                            (TSO.COUPON + TSO.DISCOUNT_FEE))                         end) as orderAmount              from TRA_SALES_ORDER tso             INNER JOIN GOO_GOODS G                ON G.ID = tso.GOODS_ID             INNER JOIN TRA_SALES_ORDER_HEADER tsoh                on TSOH.id = TSO.ORDER_HEADER_ID              left join par_party pp                on pp.id = tsoh.buyer_id             INNER JOIN WH_WARE_HOUSE wwh                ON wwh.id = tsoh.warehouse_id             WHERE tso.ORDER_STATUS > 300               and tso.ORDER_STATUS < 305               and tso.final_quantity > 0               and TSOH.Warehouse_Id in                   (select cd.domain_id                      from com_domain cd                     where cd.source_id = 1608171622470497                       and cd.source_type = 'department'                       and cd.domain_type = 'warehouse')               and G.brand_id in                   (select cd.domain_id                      from com_domain cd                     where cd.source_id = 1608171622470497                       and cd.source_type = 'department'                       and cd.domain_type = 'brand')               and G.product_id in                   (select cd.domain_id                      from com_domain cd                     where cd.source_id = 1608171622470497                       and cd.source_type = 'department'                       and cd.domain_type = 'product')               and pp.party_type = 40               and wwh.id = 1403072229050000               and tso.BRANCH_COMPANY_ID = 2               AND tso.HAS_INVOICE = 0             group by pp.id, pp.name, pp.code            UNION ALL            select pp.id as partyId,                   pp.name as partyName,                   pp.code as partyCode,                   count(tso.id) as orderNum,                   "SUM"(case                           when tsoh.order_type = 10 then                            (TSO.UNIT_PRICE * TSO.FINAL_QUANTITY -                            (tso.FINAL_QUANTITY / tso.ORDERING_QUANTITY) *                            (TSO.COUPON + TSO.DISCOUNT_FEE))                           ELSE                            (-TSO.unit_price * tso.FINAL_QUANTITY +                            (tso.FINAL_QUANTITY / tso.ORDERING_QUANTITY) *                            (TSO.COUPON + TSO.DISCOUNT_FEE))                         end) as orderAmount              from TRA_SALES_ORDER_OFFLINE tso             INNER JOIN GOO_GOODS G                ON G.ID = tso.GOODS_ID             INNER JOIN TRA_SALES_ORDER_HEADER tsoh                on TSOH.id = TSO.ORDER_HEADER_ID              left join par_party pp                on pp.id = tsoh.buyer_id             INNER JOIN WH_WARE_HOUSE wwh                ON wwh.id = tsoh.warehouse_id             WHERE tso.ORDER_STATUS > 300               and tso.ORDER_STATUS < 305               and tso.final_quantity > 0               and TSOH.Warehouse_Id in                   (select cd.domain_id                      from com_domain cd                     where cd.source_id = 1608171622470497                       and cd.source_type = 'department'                       and cd.domain_type = 'warehouse')               and G.brand_id in                   (select cd.domain_id                      from com_domain cd                     where cd.source_id = 1608171622470497                       and cd.source_type = 'department'                       and cd.domain_type = 'brand')               and G.product_id in                   (select cd.domain_id                      from com_domain cd                     where cd.source_id = 1608171622470497                       and cd.source_type = 'department'                       and cd.domain_type = 'product')               and pp.party_type = 40               and wwh.id = 1403072229050000               and tso.BRANCH_COMPANY_ID = 2               AND tso.HAS_INVOICE = 0             group by pp.id, pp.name, pp.code) tso     group by partyId, partyName, partyCode     order by orderAmount ASC) row_

where rownum <= 45;

--1608171622470497(Long), 1608171622470497(Long), 1608171622470497(Long), 40(Integer), 1511161907500008(Long), 2(Long), false(Boolean), 1608171622470497(Long), 1608171622470497(Long), 1608171622470497(Long), 40(Integer), 1511161907500008(Long), 2(Long), false(Boolean)

转载于:https://blog.51cto.com/13132636/2063328

你可能感兴趣的文章
C#~异步编程在项目中的使用
查看>>
opencv基础知识------IplImage, CvMat, Mat 的关系和相互转换
查看>>
邪淫的六种情况
查看>>
Spring中注解事务方面的问题
查看>>
[SQL]死锁处理语句
查看>>
临别前夕,工作总结 于2014年8月13日 终稿
查看>>
【floyd】HDU 1874 畅通project续
查看>>
第十篇:扩展SOUI的控件及绘图对象(ISkinObj)
查看>>
Winform开发框架中实现信息阅读状态的显示和存储
查看>>
Android 下拉刷新框架实现
查看>>
IGS_学习笔记09_IREP生成服务后台工具Soagenerate.sh
查看>>
安卓开发_浅谈ListView之分页列表
查看>>
斐波那契堆
查看>>
mongodb batchInsert
查看>>
Sun公司开源游戏服务器
查看>>
Jasmine测试ng Promises - Provide and Spy
查看>>
Response.Write具体介绍
查看>>
ARM汇编编程基础之一 —— 寄存器
查看>>
安装LVS安装LVS和配置LVS的工作比较繁杂
查看>>
Scilab 的画图函数(1)
查看>>