我想做查询。我使用微软 sql
如果 product 等于 FAST 并且 tree_level 等于 0,1,2,3,4,5 计算数字 0,1,2,3,4,5 并乘以 2 并且 tree_level 等于 -1 计算数字乘以 2
如果 product 等于 MOBIL 并且 tree_level 等于 0,1,2,3,4,5,则数乘以 3 和
如果 product 等于 FACE 并且 tree_level 等于 0,1,2,3,4,5 计算数字 0,1,2,3,4,5 并乘以 3 并且 tree_level 等于 -1 计算数字乘以 2
我想做同样的查询,但我不能做算法
连接表
perstel| AD|SOYAD|RefPhoner|Product |Tree_level
_______________________________________________
7857887|AS |DFDSF|5645545 |FAST |0
6566464|SD |DFDDS|4578857 |MOBİL |1
7487887|SD |FSDFD|8787878 |FACE |2
7487887|SD |FSDFD|8788278 |FACE |2
7487887|SD |FPOFD|8933878 |MOBIL |5
7445887|WE |FSPLD|8771878 |FACE |3
7387887|SD |LBDFD|8712878 |FAST |4
0487887|WE |FSPLD|8771878 |FACE |-1
4487887|WE |FOLLD|8771878 |MOBIL |-1
我想把它放出来我更新它以防止不稳定
perstel| AD(name at eng)|SOYAD|RefPhoner|Product |Tree_level | POint
_________________________________________________________________
7857887|AS |DFDSF|5645545 |FAST |-1 | 2 (because it is -1 and it is face so it is point 2)
6566464|EM |DFDDS|4578857 |FACE |2 | 3 (because it is 2 and it is face so it is point 3)
7487887|MM |FSDFD|8787878 |FAST |2 | 2 .....
7487887|AS |DFDSF|8788278 |MOBIL |0 | 3 ...
7487887|EM |DFDDS|8933878 |FAST |-1 | 2 ...
7445887|HL |FSPLD|8771878 |FACE |3 | 3 ...
所以我会在那之后总结人的所有点
我只这样做:(
select
DS.PersTel ,
DW.AD ,
DW.SOYAD ,
DS.RefPhoner ,
DS.Product ,
DS.Tree_level
from dw_prod.FRTN.DIG_SEFER AS DS
inner join dw_prod.dbo.DW_MUST AS DW
ON DW.CEP_TEL = DS.PersTel
我更新它我尝试了它但它仍然有错误我的错误是什么
select
DS.PersTel ,
DW.AD ,
DW.SOYAD ,
DS.RefPhoner ,
DS.Product ,
DS.Tree_level
CASE DS.Tree_level
WHEN DS.Tree_level IN (0,1,2,3,4,5) THEN count(DS.Tree_level) * 3
WHEN DS.Tree_level IN (-1) THEN count(DS.Tree_level) * 2
WHERE DS.Product like '%FACE%' END AS Answer1
CASE DS.Tree_level
WHEN DS.Tree_level IN (0,1,2,3,4,5) THEN count(DS.Tree_level) * 3
WHERE DS.Product like '%MOBIL%' END AS Answer2
CASE DS.Tree_level
WHEN DS.Tree_level IN (0,1,2,3,4,5) THEN count(DS.Tree_level) * 2
WHEN DS.Tree_level IN (-1) THEN count(DS.Tree_level) * 2
WHERE DS.Product like '%FAST%' END AS Answer3
from dw_prod.FRTN.DIG_SEFER AS DS
inner join dw_prod.dbo.DW_MUST AS DW
ON DW.CEP_TEL = DS.PersTel
更新案例部分
select
DS.PersTel ,
DW.AD ,
DW.SOYAD ,
DS.RefPhoner ,
DS.Product ,
DS.Tree_level
CASE
WHEN DS.Tree_level IN (0,1,2,3,4,5)AND DS.Product LIKE '%FACE%' THEN count(DS.Tree_level) * 3
WHEN DS.Tree_level IN (-1) THEN count(DS.Tree_level) * 2
END AS Answer1
CASE DS.Tree_level
WHEN DS.Tree_level IN (0,1,2,3,4,5) AND DS.Product LIKE '%MOBIL%' THEN count(DS.Tree_level) * 3
END AS Answer2
CASE DS.Tree_level
WHEN DS.Tree_level IN (0,1,2,3,4,5) AND DS.Product LIKE '%FAST%' THEN count(DS.Tree_level) * 2
WHEN DS.Tree_level IN (-1) THEN count(DS.Tree_level) * 2
END AS Answer3
from dw_prod.FRTN.DIG_SEFER AS DS
inner join dw_prod.dbo.DW_MUST AS DW
ON DW.CEP_TEL = DS.PersTel