我想在SQL Server中找到这两个选择的总和:

select count(rez1)*3 as Fit1 from Table_Name where rez1>rez2

select count(rez1)*1 as Fit2 from Table_Name where rez1=rez2

最佳答案

您可以将where子句转换为case表达式并返回整数值,然后可以将它们相加:

SELECT SUM (CASE WHEN rez1 > rez2 THEN 3
                 WHEN rez1 = rez2 THEN 1
            END)
FROM   table_name

10-08 05:14