直接出動銷率的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

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章