spark SQL 中 连续12个月发货值和收货值为空值或者0 则过滤该产品
时间: 2024-05-09 15:20:56 浏览: 73
可以使用以下SQL语句实现:
```
SELECT *
FROM product_table
WHERE NOT (
(shipping_value_1 = 0 OR shipping_value_1 IS NULL)
AND (shipping_value_2 = 0 OR shipping_value_2 IS NULL)
AND (shipping_value_3 = 0 OR shipping_value_3 IS NULL)
AND (shipping_value_4 = 0 OR shipping_value_4 IS NULL)
AND (shipping_value_5 = 0 OR shipping_value_5 IS NULL)
AND (shipping_value_6 = 0 OR shipping_value_6 IS NULL)
AND (shipping_value_7 = 0 OR shipping_value_7 IS NULL)
AND (shipping_value_8 = 0 OR shipping_value_8 IS NULL)
AND (shipping_value_9 = 0 OR shipping_value_9 IS NULL)
AND (shipping_value_10 = 0 OR shipping_value_10 IS NULL)
AND (shipping_value_11 = 0 OR shipping_value_11 IS NULL)
AND (shipping_value_12 = 0 OR shipping_value_12 IS NULL)
AND (receiving_value_1 = 0 OR receiving_value_1 IS NULL)
AND (receiving_value_2 = 0 OR receiving_value_2 IS NULL)
AND (receiving_value_3 = 0 OR receiving_value_3 IS NULL)
AND (receiving_value_4 = 0 OR receiving_value_4 IS NULL)
AND (receiving_value_5 = 0 OR receiving_value_5 IS NULL)
AND (receiving_value_6 = 0 OR receiving_value_6 IS NULL)
AND (receiving_value_7 = 0 OR receiving_value_7 IS NULL)
AND (receiving_value_8 = 0 OR receiving_value_8 IS NULL)
AND (receiving_value_9 = 0 OR receiving_value_9 IS NULL)
AND (receiving_value_10 = 0 OR receiving_value_10 IS NULL)
AND (receiving_value_11 = 0 OR receiving_value_11 IS NULL)
AND (receiving_value_12 = 0 OR receiving_value_12 IS NULL)
)
```
其中,`product_table`是产品表的表名,`shipping_value_1`到`shipping_value_12`是连续12个月的发货值字段,`receiving_value_1`到`receiving_value_12`是连续12个月的收货值字段。该SQL语句使用了NOT运算符和AND运算符来判断连续12个月的发货值和收货值是否为空或为0,如果都为空或为0,则过滤该产品。
阅读全文