select pro_c_id from ( select pro_c_id, count(pro_c_id) as cnt1, cnt2 from ( select pro_c_id, pro_pif_id, ( select count(*) from ( select pro_pif_id from property where pro_type = 1 group by pro_pif_id having count(distinct(pro_c_id)) > 2 ) as t1 ) as cnt2 from property as p natural join ( select pro_pif_id from property where pro_type = 1 group by pro_pif_id having count(distinct(pro_c_id)) > 2 ) as t2 where pro_type = 1 order by pro_c_id ) as t3 group by pro_c_id ) as t4 where cnt1 = cnt2
时间: 2024-02-14 11:33:43 浏览: 63
这是一个SQL语句,用于查询拥有至少三个不同产品的公司的ID。具体的查询条件是:
首先从属性表中选择属性类型为1的记录,并计算每个产品被多少个公司所拥有,将结果作为t1表。然后从t1表中选择拥有至少三个不同公司的产品ID,将结果作为t2表。
接下来从属性表中选择属性类型为1的记录,并将其与t2表进行自然连接操作,得到拥有t2表中产品的属性记录,将结果作为t3表。在t3表中,根据公司ID进行分组,并计算每个公司拥有的属性记录数量和t2表的记录数量,将结果作为t4表。
最后在t4表中,选择属性记录数量等于t2表记录数量的公司,并返回它们的ID。
相关问题
select create_date ,major_biz_name ,minor_biz_name ,minimal_biz_name ,call_type ,service_line ,finance_type ,min_cnt ,finance_user_cnt from from ( select '${zdt.addDay(-1).format("yyyy-MM")}' create_date ,major_biz_name ,minor_biz_name ,minimal_biz_name ,call_type ,service_line ,finance_type ,count(1) min_cnt from dm_pay.finance_call_in_cnt_di where substr(cast(day as string),1,6)='${zdt.addDay(-1).format("yyyyMM")}' group by major_biz_name ,minor_biz_name ,minimal_biz_name ,call_type ,service_line ,finance_type ) a left join ( select max(user_cnt) finance_user_cnt from --dm_njbi.cc_damage_kpi_v2_di dm_njbi.active_user_30days_finance_di where day =${zdt.addDay(-1).format("yyyyMMdd")} ) b on 1=1 ; sql哪里不合法
您的SQL语句中存在一处不合法的地方,即在最外层的FROM子句之后没有指定要查询的表名或子查询。您需要将要查询的表名或子查询添加到FROM子句中,例如:
```sql
SELECT
create_date,
major_biz_name,
minor_biz_name,
minimal_biz_name,
call_type,
service_line,
finance_type,
min_cnt,
finance_user_cnt
FROM (
SELECT
'${zdt.addDay(-1).format("yyyy-MM")}' AS create_date,
major_biz_name,
minor_biz_name,
minimal_biz_name,
call_type,
service_line,
finance_type,
COUNT(1) AS min_cnt
FROM dm_pay.finance_call_in_cnt_di
WHERE SUBSTR(CAST(day AS STRING), 1, 6) = '${zdt.addDay(-1).format("yyyyMM")}'
GROUP BY
major_biz_name,
minor_biz_name,
minimal_biz_name,
call_type,
service_line,
finance_type
) a
LEFT JOIN (
SELECT MAX(user_cnt) AS finance_user_cnt
FROM dm_njbi.active_user_30days_finance_di
WHERE day = ${zdt.addDay(-1).format("yyyyMMdd")}
) b ON 1=1;
```
请将您要查询的表名或子查询添加到相应位置后重新执行查询。
create table if not exists tb_rs_sex_cnt comment "发送消息性别" as select dayinfo, sender_sex, distinct sender_account, count(sender_sex) as sender_sex_cnt from tb_msg_etl group by sender_sex;
这是一条SQL语句,用于在数据库中创建名为“tb_rs_sex_cnt”的表。如果该表不存在,则会创建该表。该表包括以下列:
- dayinfo:日期信息
- sender_sex:发送消息的性别
- sender_account:发送消息的账号
- sender_sex_cnt:发送消息的性别数量
该表是通过对名为“tb_msg_etl”的表进行查询并进行分组计数得到的。
阅读全文