有人可以告诉我我的查询出了什么问题吗?我肯定知道where子句中的case语句肯定有问题。没有Case语句,此查询将正常运行。
错误– SELECT失败。 3707:语法错误,应该是类似“)”和“> =”之间的“ END关键字”
SELECT
mp.chnl_name AS mp_channel,
fsk.sku_prod_id AS pro_id,
fsk.dateint AS avlbl_dt,
fsk.sku_num AS sku,
fsk.upc_txt AS UPC,
Coalesce(fsk.brand_name,'N/A') AS brand,
fsk.ruckload AS LTL_Flag,
fsk.price_amt AS item_selling_price,
fsk.on_hand_unit_qty AS qoh,
fsk.netpropt AS profite,
(fsk.price_amt + fsk.shpg_amt) AS lms,
(GP)*100 AS net_pct
FROM EDW.ITEM_AVLBL mp
JOIN EDW.FULL_SKU fsk ON mp.item_id = fsk.item_id
JOIN EDW.SHORT_SKU ssk ON ssk.sh_sku_id = fsk.sh_sku_id
WHERE 1=1
AND mp.chnl_name LIKE '%google%' ---------- This is a prompt but I hard coded to test
AND fsk.item_create_dt >= '2019-10-20'
AND net_pct >= 10
AND CASE WHEN mp.chnl_name = 'CA_FACEBOOK' THEN ((GP)*100) >= 7 ELSE fsk.first_cost > 500 END
GROUP BY 1,2,3,4,5,6,7,8,9,10,11,fsk.first_cost
有人可以告诉我如何解决此问题吗?
答案 0 :(得分:1)
案例在这里不起作用,您可以重写以使用AND和OR
AND ( (mp.chnl_name = 'CA_FACEBOOK' AND ((GP)*100) >= 7 )
OR (mp.chnl_name != 'CA_FACEBOOK' AND fsk.first_cost > 500) )
根据您在下面所说的内容,将以下内容添加到where:
AND ( (mp.chnl_name = 'CA_FACEBOOK' AND ((GP)*100) >= 7 AND fsk.first_cost > 500)
OR mp.chnl_name != 'CA_FACEBOOK'
)
答案 1 :(得分:0)
请勿使用CASE
:
( (mp.chnl_name = 'CA_FACEBOOK' AND ((GP)*100) >= 7) OR
(mp.chnl_name <> 'CA_FACEBOOK' AND fsk.first_cost > 500)
)
问题是Teradata不支持从CASE
表达式返回布尔类型。因此,您在THEN
子句中所做的比较在语法上不会被理解。
编辑:
根据您的评论,您想要的逻辑是:
( (mp.chnl_name = 'CA_FACEBOOK' AND ((GP)*100) >= 7 AND fsk.first_cost > 500
) OR
(mp.chnl_name <> 'CA_FACEBOOK' )
)
答案 2 :(得分:0)
这可能是您想要的:
WHERE
(mp.chnl_name <> 'CA_FACEBOOK'
AND mp.chnl_name LIKE '%google%' ---------- This is a prompt but I hard coded to test
AND fsk.item_create_dt >= '2019-10-20'
AND net_pct >= 10
OR (( mp.chnl_name = 'CA_FACEBOOK' AND GP*100 >= 7 AND fsk.first_cost > 500))
但是,如果要在应用程序中创建此WHERE条件(1=1
似乎表明了这一点),则最好在此应用逻辑。
答案 3 :(得分:0)
根据您的评论,应该将原始的ELSE条件改为“与”:
tree
我不希望您要GROUP_first_cost。并且隐式地假定mp.chnl_name不为NULL,因此它等于CA_FACEBOOK或不等于。如果允许使用NULL,则还需要明确检查该条件,例如from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
ff_options = Options()
#profile
binary = FirefoxBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe")
profile = webdriver.FirefoxProfile('C:\\Users\\bravoj\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\7k4o5psw.CCC Deafualt')
ff_driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, executable_path='C:\\Users\\bravoj\Downloads\\geckodriver.exe')
#fire fox driver
ff_driver.get('about:profiles')
。
答案 4 :(得分:0)
这就是我的工作方式,但我可能会在说明中混淆你们。非常感谢您的快速回复。非常感谢您的帮助和时间。
AND (CASE WHEN mp.sls_trans_web_orgn_chnl_name = 'CA_FACEBOOK' AND fsk.full_sku_unit_first_cost < 500 AND (juice/NullIfZero(gms))*100 >= 7 THEN 1
WHEN mp.sls_trans_web_orgn_chnl_name <> 'CA_FACEBOOK' THEN 1 ELSE 0 END ) = 1