這是一個簡單的過程在excel中使用vlookup與近似匹配,但由於某些原因,我無法使其與SQl一起工作,我確信我正在以這種方式執行此任何幫助,我們將不勝感激。這是我得到的結果的一個樣本:X和Y之間的貨幣價值?
Player ID ADT ADT Tier
103 31.25 2
112 6.03 6
114 498.26 7
117 1330.82 4
131 10.01 NULL
這裏是一個樣本應該是什麼樣子:
Player ID ADT ADT Tier
103 31.25 11
112 6.03 NULL
114 498.26 7
117 1330.82 4
131 10.01 NULL
下面是我想使用的代碼。
Select S.Meta_ID as "Player ID"
,Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2) as ADT
,case
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '3500' and '1000000' then '1'
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '2000' and '3499.99' then '2'
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '1500' and '1999.99' then '3'
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '1000' and '1499.99' then '4'
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '750' and '999.99' then '5'
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '500' and '749.99' then '6'
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '300' and '499.99' then '7'
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '150' and '299.99' then '8'
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '75' and '149.99' then '9'
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '40' and '74.99' then '10'
when cast(Round(Sum(S.TWin)/Nullif(Count(Distinct S.GamingDate),0),2)as varchar) between '15' and '39.99' then '11'
Else null
End as "ADT Tier"
From dbo.CDS_STATDAY as S
Where S.GamingDate Between '06/1/2014' and '08/31/2014'
And S.IDType = 'P'
And S.StatType <> 'Poker'
Group by S.Meta_ID
你可以提供來自CDS_STATDAY表的樣本數據,還有哪些RDBMS? – radar 2014-10-01 17:17:44
你爲什麼要轉換爲varchar做一個數字比較? – 2014-10-01 17:19:07
你的問題是試圖比較轉換爲字符串的數字,只是使用數字值。此外,轉換時總是指定一個大小,只是使用「varchar」非常懶。當只使用「varchar」時,你知道默認大小是什麼嗎?你的數據會適合它嗎?添加大小並不需要太多:'varchar(25)'。 – 2014-10-01 18:49:36