直接出动销率的sql报表

公司原来手工处理销售库存的人员统计货品动销率要好几天时间,为方便查询货品动销率,同时系统支持自定义报表,用sql研究了下,可用的sql语法如下

mmf为货品档案表,stock为库存表每个货品货号matid对应多个仓库,matoutlist为出货明细表,a开头的编号表示销售出货,supplylist为配货明细表,已签发的不在任何库存中

 

SELECT T3.NAME,T3.matid,t3.provcode,t3.model,t3.model3,t3.banid,t3.model1,t3.model2,t3.property1,CAST(ISNULL(t3.quoteprice,0) AS varchar) as quote,(t4.STOCKQTY+isnull(T6.stockqty,0)) as STOCKQTY,T3.OUTQTY,

CASE ISNULL((T4.STOCKQTY+isnull(T6.STOCKQTY,0)+T3.outqty),0) WHEN 0 THEN null

ELSE CONVERT(NUMERIC(11,2),CAST(ISNULL(T3.OUTQTY,0) AS FLOAT)/CAST(ISNULL((T4.STOCKQTY+isnull(T6.STOCKQTY,0)+T3.outqty),0) AS FLOAT)) END AS XIAOLV,

(T4.STOCKQTY+isnull(T6.stockqty,0))*T3.quoteprice as stockacc,

t3.outqty*t3.quoteprice as outacc

FROM

(

SELECT T1.NAME,T1.matid,t1.model,t1.model1,t1.model2,t1.property1,T1.quoteprice,t1.provcode,t1.model3,t1.banid,SUM(ISNULL(T2.QTY,0)) AS OUTQTY

FROM MMF as T1

LEFT JOIN MATOUTLIST as T2

ON T1.MATID = T2.MATID and t2.matioid like 'a%'

left join matout as t3 on t2.matioid=t3.matioid and t3.state='已入账'  

GROUP BY T1.NAME,t1.matid,t1.quoteprice,t1.model,t1.model1,t1.model2,t1.property1,t1.provcode,t1.model3,t1.banid

) as T3

 

INNER JOIN

 

(

SELECT T1.NAME,T1.matid,t1.model,t1.model1,t1.model2,t1.property1,t1.quoteprice,t1.provcode,t1.model3,t1.banid,SUM(ISNULL(T2.QTY,0)) AS STOCKQTY

FROM MMF as T1

LEFT JOIN STOCK as T2

ON T1.MATID = T2.MATID

GROUP BY T1.NAME,t1.matid,t1.quoteprice,t1.model,t1.model1,t1.model2,t1.property1,t1.provcode,t1.model3,t1.banid

) as T4

 

ON T3.matid = T4.matid and t3.matid<>'000002' and t3.matid<>'000001'          ----不显示非正常货品

left JOIN

 

(

SELECT T1.NAME,T1.matid,t1.model,t1.model1,t1.model2,t1.property1,t1.quoteprice,t1.provcode,t1.model3,t1.banid,SUM(ISNULL(T2.QTY,0)) AS STOCKQTY

FROM MMF as T1

LEFT JOIN supplylist as T2 ON T1.MATID = T2.MATID left join supply as t5 on t2.poid=t5.poid where t5.state='已签发'

GROUP BY T1.NAME,t1.matid,t1.quoteprice,t1.model,t1.model1,t1.model2,t1.property1,t1.provcode,t1.model3,t1.banid

) as T6


ON T3.matid=t6.matid

 

order by xiaolv desc

 

 

 

 

 

 

 

你可能感兴趣的:(直接出动销率的sql报表)