Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL Server查询搜索将特定值匹配放在顶部_Sql_Sql Server_Search - Fatal编程技术网

SQL Server查询搜索将特定值匹配放在顶部

SQL Server查询搜索将特定值匹配放在顶部,sql,sql-server,search,Sql,Sql Server,Search,我有一个问题: select Product.TblProducts.Product_ID, Product.TblProducts.Product_Name, Product.TblProducts.Country from Product.TblProducts WHERE (Product.TblProducts.Domain = 'mysite.co.uk') 问题: 我想展示所有产品,但我想展示国家=英国的产品,以获得高度优先权,并在顶部展

我有一个问题:

select Product.TblProducts.Product_ID, 
       Product.TblProducts.Product_Name,     
       Product.TblProducts.Country 
from Product.TblProducts 
WHERE (Product.TblProducts.Domain = 'mysite.co.uk')
问题: 我想展示所有产品,但我想展示国家=英国的产品,以获得高度优先权,并在顶部展示,因为该领域是英国

我需要一个排序机制来做这件事

非常感谢您的帮助。

您可以按以下顺序使用案例陈述:

请尝试:

select 
    Product.TblProducts.Product_ID, 
    Product.TblProducts.Product_Name,     
    Product.TblProducts.Country 
from 
    Product.TblProducts 
    WHERE  (Product.TblProducts.Domain = 'mysite.co.uk')
order by (CASE WHEN Country = 'United Kingdom' THEN 1 else 0 end) desc
select 
    Product.TblProducts.Product_ID, 
    Product.TblProducts.Product_Name,     
    Product.TblProducts.Country 
from 
    Product.TblProducts 
    WHERE  (Product.TblProducts.Domain = 'mysite.co.uk')
order by (CASE WHEN Country = 'United Kingdom' THEN 1 else 0 end) desc