select Prefered_supplier,VENDOR_NAME,VENDOR_SITE_CODE
from ( select SUPPLIER_ID,SUPPLIER_SITE_ID,
VENDOR_NAME, VENDOR_SITE_CODE ,Approved_supplier,Prefered_supplier
from xx_po_vendorssites_v
order by (case Approved_supplier='YES' and Preffered_supplier ='YES'
THEN Prefered_supplier END) DESC,
VENDOR_NAME ASC,
VENDOR_SITE_CODE ASC
);
供应商的分类如下:
它没有按预期工作。请帮忙。
答案 0 :(得分:2)
也许我错过了什么,但外部查询对我来说似乎没有必要。我的方法是:
select Prefered_supplier,VENDOR_NAME,VENDOR_SITE_CODE
from xx_po_vendorssites_v
order by case
WHEN Approved_supplier='YES' and Preffered_supplier ='YES' THEN 1
WHEN Approved_supplier='NO' and Preffered_supplier ='YES' THEN 2
ELSE 3
END ASC, VENDOR_NAME ASC, VENDOR_SITE_CODE ASC
答案 1 :(得分:1)
作为一个说明,我认为你可以简化逻辑:
order by Preffered_supplier desc, Approved_supplier desc,
vendor_name, vendor_site_code
答案 2 :(得分:0)
这有用吗?
select Prefered_supplier,VENDOR_NAME,VENDOR_SITE_CODE
from ( select SUPPLIER_ID,SUPPLIER_SITE_ID,
VENDOR_NAME, VENDOR_SITE_CODE ,Approved_supplier,Prefered_supplier
from xx_po_vendorssites_v
order by DECODE(preferred_supplier||Approved_supplier, 'YESYES', 1, 0) DESC,
DECODE(preferred_supplier, 'YES', 1, 0) DESC, supplier,
VENDOR_NAME ASC,
VENDOR_SITE_CODE ASC
);