with t1 as ( select distinct driver_id, cargo_id, recallroad from dm_algo.reflow_feed_base_data_di_v2 where day = 20230604 and json_tuple( get_json_object(poolsourceinfo, "$.HOMEPAGE_RECOMMEND"), "2" ) is not null ), t2 as ( select driver_id, cargo_id from dm_dtmart.cargo_deal_channel_listen_dispatch_specific_di where day = 20230604 and project_type in ('零担拼车', '平台普货', '特运通', '委托货') and driver_id % 10 between 0 and 4 ) select t1 join t2 on t1.driver_id=t2.driver_id and t1.cargo_id=t2.cargo_id
时间: 2024-04-27 10:20:43 浏览: 9
这是一段 SQL 查询语句,用于从两个数据表中获取特定条件下的数据。首先,使用了一个子查询 t1,从 dm_algo.reflow_feed_base_data_di_v2 表中筛选出符合以下条件的数据:日期为 20230604,且该行数据的 poolsourceinfo 字段中的第二个元素不为空。然后,使用另一个子查询 t2,从 dm_dtmart.cargo_deal_channel_listen_dispatch_specific_di 表中筛选出符合以下条件的数据:日期为 20230604,且 project_type 字段的值为 '零担拼车'、'平台普货'、'特运通' 或 '委托货',且 driver_id 取模 10 的结果在 0~4 之间。最后,将 t1 和 t2 进行内连接(join),并根据 driver_id 和 cargo_id 进行匹配。
相关问题
把SELECT count(DISTINCT user_id) from rams_ol_case语句转为elasticsearch语句
在 Elasticsearch 中,可以使用聚合(Aggregation)功能来实现类似于 SQL 中 `SELECT count(DISTINCT user_id) from rams_ol_case` 的查询。具体的实现步骤如下:
1. 创建一个索引并插入数据,例如:
```
PUT my_index/_doc/1
{
"user_id": 1,
"case_name": "case1"
}
PUT my_index/_doc/2
{
"user_id": 2,
"case_name": "case2"
}
PUT my_index/_doc/3
{
"user_id": 1,
"case_name": "case3"
}
PUT my_index/_doc/4
{
"user_id": 3,
"case_name": "case4"
}
```
2. 使用聚合功能进行去重计数,例如:
```
POST my_index/_search
{
"size": 0,
"aggs": {
"distinct_users": {
"cardinality": {
"field": "user_id"
}
}
}
}
```
这个聚合查询会对 `user_id` 字段进行去重计数,得到不同的用户数。执行结果如下:
```
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"distinct_users": {
"value": 3
}
}
}
```
这个结果表明,不同的用户数是 3。
select distinct tablespace_name from all_tables group by tablespace_name
在 SQL 中,你的查询语句是有问题的。你不能在使用 `GROUP BY` 之前使用 `DISTINCT` 关键字。如果你想获取所有表的唯一的 `tablespace_name`,你可以使用以下查询语句:
```sql
SELECT DISTINCT tablespace_name
FROM all_tables;
```
这个查询语句将返回 `all_tables` 表中唯一的 `tablespace_name` 值。每个不同的 `tablespace_name` 将作为结果返回,重复的值将被过滤掉。