求救,关于售价的SQL药品检索语句, 用case when

来源:百度知道 编辑:UC知道 时间:2024/06/26 04:22:43
需满足条件如下:1.如果有历史售价且无促销价,那么就用历史售价;
2.如果无历史售价,那么就用设定价;
3.如果设定价已调整,那么就用调整价。
我是这么写的:
case when h.diaocdj is not null and h.diaocdj>0 then h.diaocdj ---促销售价
else case when j.diaocdj is not null then j.diaocdj ---特殊售价
else case when left(a.spbh,1)='z' then case WHEN b.jgtx_zy='A' and (历史 is null or 上次采购后调整了) THEN d.ydjg else 历史售价 end --药店价格
case WHEN b.jgtx_zy='B' and (历史 is null or 上次采购后调整了) THEN d.yljgjg else 历史售价 end --医疗机构价格
case WHEN b.jgtx_zy='C' and (历史 is null or 上次采购后调整了) THEN d.syjgjg else 历史售价 end--商业价格
end
end
end

CASE WHEN ISNULL(历史售价,'')<>'' AND ISNULL(促销价,'')='' THEN 历史售价
WHEN ISNULL(历史售价,'')='' THEN 设定价
WHEN ISNULL(调整价,'')<>'' THEN 调整价
ELSE 0 END

大概这样吧 你那个我看不懂

不用case when 似乎还简单一点啊