在特定条件下选择一条记录

时间:2018-01-24 21:53:12

标签: sql sql-server

我想写一个查询,当它满足一定条件时选择一条记录。

表: table

使用此表,我不想选择具有Contract_number'MDE'的记录,但如果只有一个记录带有claimnumber,即使Contract_number是'MDE',我也想选择它。

1 个答案:

答案 0 :(得分:1)

您可以订购数据并拍摄第一张唱片

select top 1 *
from your_table
where claim_number = 17428835
order by case when contract_number <> 'MDE' then 1 else 2 end
相关问题