[英]Teradata SQL - Conditions depending on conditions in WHERE clause
This question is a variation on an older post 这个问题是旧帖子的变体
The conditions 条件
If Customer_country = 'A' 如果Customer_country ='A'
then Ship_country must = 'A' 那么Ship_country必须='A'
and Customer_number <> 'A2' (ie exclude A2) 和客户编号<>'A2'(即排除A2)
and date is between x and y. 日期在x和y之间。 (same for all Customer country) (适用于所有客户国家/地区)
The same logic goes for all Customer_country, where respective B2, C2, D2 Customer_numbers are excluded. 相同的逻辑适用于所有Customer_country,其中分别排除了B2,C2,D2 Customer_number。
I am confused with using CASE…WHEN because it is expected to return a value. 我对使用CASE…WHEN感到困惑,因为它期望返回一个值。
But I am not returning any value. 但是我没有返回任何价值。 Please help with this query. 请帮助此查询。
You should use where
clause instead of case when
您应该使用where
子句而不是case when
Using ||
使用||
method to combine char like A2
or B2
... ,then you can exclude that. 组合像A2
或B2
...这样的char的方法,那么您可以排除它。
SELECT *
FROM master as t1
WHERE
t1.Customer_number <> t1.Customer_Country || '2'
AND
t1.Ship_Country = t1.Customer_Country
EDIT 编辑
if the customer_number is like '981432776',you can use NOT IN
to exclude that. 如果customer_number类似于'981432776',则可以使用NOT IN
排除它。
SELECT *
FROM master as t1
WHERE
t1.Customer_number NOT IN ('A2','B2','C2','D2')
AND
t1.Ship_Country = t1.Customer_Country
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.