SELECT * FROM dw.ol_autotask_model_channels_predict_content WHERE dt BETWEEN '20230601' AND '20230630' AND predict in ('other','middle') AND (cust_id, dt) not in ( SELECT cust_id, dt FROM dw.ol_autotask_model_channels_predict_content WHERE dt BETWEEN '20230601' AND '20230630' AND predict = 'travel' ) AND cust_id is not null
时间: 2024-02-14 16:24:51 浏览: 57
autotask_puppeteer
您的第一个问题是关于SQL查询的。您想要在2023年6月日至2023年月30日期间,预为"other"或"middle"且不包含预测为"travel"的客户信息。同时,您希望排除_id为空的记录。
以下是您的SQL查询句:
```sql
SELECT *
FROM dw.ol_autask_model_channels_predict_content
WHERE dt BETWEEN '20230601' AND '20230630'
AND predict IN ('other', 'middle')
AND (cust_id, dt) NOT IN (
SELECT cust_id, dt
FROM dw.ol_autotask_model_channels_predict_content
WHERE dt BETWEEN '20230601' AND '20230630'
AND predict = 'travel'
)
AND cust_id IS NOT NULL;
```
请注意,这个查询涉及到两个表的自我关联,并使用了子查询来排除预测为"travel"的记录。同时,通过使用`NOT IN`和`IS NOT NULL`条件来排除cust_id为空的记录。
请确保替换表名、字段名和日期范围以适应您的实际数据库结构和数据。
阅读全文