关于查询优先级的问题
dgyig 2017-03-01 02:56:46 有这样一个表T 商品加顾客作为唯一索引
goods client discount
a 张三 0.7 //代表张三单独对a商品有7折优惠
张三 0.8 // 代表张三对所有商品都有8折优惠
a 0.9 //代表商品a的通用优惠
b 0.9
商品加顾客作为条件。目前希望select时。优先查找goods跟client都不为空时的折扣。若不存在。则再查找goods为空client不为空时的折扣。 若还是没有记录。则最后查找出商品的通用优惠。
目前我是用的
select discount from T where goods =@goods and discount=@discount
if 结果为空 then
select discount from T where goods is null and discount=@discount
if 结果为空
。。。。。
请问有没有方法能在一个select语句里面实现这种逻辑?