oracle中用case when查询列表
查询sql语句如下
SELECT * FROM (
SELECT *
,ROW_NUMBER() OVER ( PARTITION BY scene_code ORDER BY (CASE status when 'DRAFT' then 3 when 'PRE' then 5 when 'GRAY' then 7 when 'PROD' then 9 END) DESC ) AS rank_id
FROM fus_recom_config
WHERE status in ('DRAFT','PRE','GRAY','PROD')
) a
WHERE a.rank_id=1
ORDER BY a.gmt_modified DESC
LIMIT 0,200
查询结果为 当scene_Code相同时,会按status(PROD>GRAY>PRE>DRAFT)返回最高状态的一条数据,不会同时出现scene_Code相同的多条数据