复制代码
- SELECT sSalesName=LEFT(d.sSalesName,1)+'**'
- ,sMonth=CONVERT(NVARCHAR(7),a.dReceivedDate,120),nQty=SUM(c.nQty)
- FROM dbo.sdOrderHdr a
- JOIN dbo.sdOrderDtl b ON b.usdOrderHdrGUID = a.uGUID
- JOIN dbo.sdOrderLot c ON c.usdOrderDtlGUID = b.uGUID
- JOIN dbo.pbSales d ON d.uGUID = a.upbSalesGUID
- WHERE dReceivedDate BETWEEN '20130101' AND '20131231'
- GROUP BY LEFT(d.sSalesName,1)+'**',CONVERT(NVARCHAR(7),a.dReceivedDate,120)
- ORDER BY 1,2,3 desc
复制代码
- SELECT sMonth=CONVERT(NVARCHAR(7),a.dReceivedDate,120),
- 业务员_陈=SUM(CASE WHEN d.sSalesName LIKE '陈%' then c.nQty ELSE 0 END ) ,
- 业务员_方=SUM(CASE WHEN d.sSalesName LIKE '方%' then c.nQty ELSE 0 END ) ,
- 业务员_高=SUM(CASE WHEN d.sSalesName LIKE '高%' then c.nQty ELSE 0 END )
- FROM dbo.sdOrderHdr a
- JOIN dbo.sdOrderDtl b ON b.usdOrderHdrGUID = a.uGUID
- JOIN dbo.sdOrderLot c ON c.usdOrderDtlGUID = b.uGUID
- JOIN dbo.pbSales d ON d.uGUID = a.upbSalesGUID
- WHERE dReceivedDate BETWEEN '20130101' AND '20131231'
- GROUP BY CONVERT(NVARCHAR(7),a.dReceivedDate,120)
- ORDER BY 1
表格设置
欢迎光临 环思产品论坛 (http://bbs.huansi.cn/) | Powered by Discuz! X3.2 |