我必须运行查询才能找到价格。我有多个价目表,每个价目表都有自己的表。customer_price、default_price 和 minimum_price。
并非所有价目表都包含所有产品,有时产品可能不会出现在任何价目表上,然后价格需要为价格返回 0。
所以我想:
select price from customer_price where customer='walmart' and product='whitebread'
如果这返回结果,那么一切都很好。如果结果为 0,NULL 或查询不返回任何行,我希望它运行:
select price from default_price where customer='walmart' and product='whitebread'
如果这返回结果,那么一切都很好。如果结果为 0,NULL 或查询不返回任何行,我只想返回 0。
我不确定如何进行。我尝试了一个 case 语句,但如果在结果中找不到任何行,case 语句就会失败。我该怎么做或说if 0 results then
预先感谢,一如既往。