I want to do query. I use Microsoft SQL.
- If product is equal to FAST...
- and tree_level is equal 0,1,2,3,4,5, then count the number of 0,1,2,3,4,5. For example if there is number of 30 item which contain "0,1,2,3,4,5". Then multiply 30*2.
- and tree_level equal -1, then count number of -1 and multiply by 2
- If product is equal to MOBIL and tree_level is equal 0,1,2,3,4,5 count the number and multiply by 3
- If product is equal to FACE...
- and tree_level is equal to 0,1,2,3,4,5, then count the number of 0,1,2,3,4,5 and multiply by 3
- and tree_level equal -1, then count number of -1 and multiply by 2
How can ı use where, case and counter statements together? I can not do that.
select
DS.PersTel ,
DW.AD ,
DW.SOYAD ,
DS.RefPhoner ,
DS.Product ,
DS.Tree_level
WHERE DS.Product like '%FACE%' (
CASE
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
END
WHERE DS.Product like '%MOBIL%' (
CASE DS.Tree_level
WHEN DS.Tree_level IN (0,1,2,3,4,5) THEN count(DS.Tree_level) * 3
END )
WHERE DS.Product like '%FAST%' (
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
END )
from dw_prod.FRTN.DIG_SEFER AS DS
inner join dw_prod.dbo.DW_MUST AS DW
ON DW.CEP_TEL = DS.PersTel
updated case part
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 d.FR AS Ds
inner join d.dbo.DW AS Dw
ON DW.CEP_TEL = DS.PersTel