|
终于写完了,谢谢大家
select * from (Select department, item_code, min(purchase_price)as purchase_price from (SELECT *,'purchase_price' =
CASE
WHEN getdate()>(begin_year+'/'+begin_month+'/'+begin_day) and getdate()<(end_year+'/'+end_month+'/'+end_day) THEN purchase_price_p
WHEN getdate()<(begin_year+'/'+begin_month+'/'+begin_day) or getdate() >(end_year+'/'+end_month+'/'+end_day) THEN purchase_price_n
END
FROM fresh_purchase_price) as a
Group by department, item_code) as b inner join (SELECT *,'purchase_price' =
CASE
WHEN getdate()>(begin_year+'/'+begin_month+'/'+begin_day) and getdate()<(end_year+'/'+end_month+'/'+end_day) THEN purchase_price_p
WHEN getdate()<(begin_year+'/'+begin_month+'/'+begin_day) or getdate() >(end_year+'/'+end_month+'/'+end_day) THEN purchase_price_n
END
FROM fresh_purchase_price) as c on b.department=c.department and b.item_code = c.item_code
and b.purchase_price=c.purchase_price |
|