日期:2014-05-17 浏览次数:20507 次
SELECT
e.equip_id,
e.equip_name,
f.fact_name,
ed.dept_name,
eb.buy_date,
eb.price,
dp.months/12 AS depr_year,
CASE
WHEN datediff(month,dp.start_date,GETDATE()) >= dp.months THEN eb.price
WHEN datediff(month,dp.start_date,GETDATE()) < dp.months THEN eb.price / dp.months * datediff(month,dp.start_date,GETDATE())
END AS depr_amount,--折旧金额= 设备原值/ 折旧期限* 使用时间
CASE
WHEN datediff(month,dp.start_date,GETDATE()) >= dp.months THEN '0'
WHEN datediff(month,dp.start_date,GETDATE()) < dp.months THEN eb.price - eb.price / dp.months * datediff(month,dp.start_date,GETDATE())
END AS equip_worth, --净值 = 设备购置金额 - 已设备折旧金额
SUM(dtl.EQUIP_USE_NUM) AS USE_NUM, --使用次数
SUM(dtl.PERCENT_FEE) AS PERCENT_FEE --费用
FROM
AMS_PERFORM_EQUIP pe
LEFT JOIN AMS_EQUIP e ON pe.EQUIP_ID = e.equip_id
LEFT JOIN AMS_EQUIP_BUY eb ON e.buy_id = eb.buy_id
LEFT JOIN AMS_FACTORY f ON f.fact_id = eb.product_id
LEFT JOIN AMS_EQUIP_DEPT ed ON e.equip_id = ed.equip_id
LEFT JOIN temp_equip_perform_dtl temp ON temp.EQUIP_ID = e.equip_id
LEFT JOIN AMS_EQUIP_PERFORM_DTL dtl ON e.equip_id = dtl.EQUIP_ID AND pe.status = '正常'
LEFT JOIN AMS_DEPRECIATION_PLAN dp ON e.equip_id = dp.equip_id
WHERE temp.perform_year = '2012' AND temp.perform_month = '12' --加where后 执行需要14秒
GROUP BY
e.equip_id,
e.equip_name,
f.fact_name,
ed.dept_name,
eb.buy_date,
eb.price,
dp.months,
dp.start_date,
dtl.PROJECT_FEE,
dtl.PROJECT_UNIT