クエリを実行したい。Microsoft 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