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 20:33:43 浏览: 24
这是一个SQL语句,用于查询拥有至少三个不同产品的公司的ID。具体的查询条件是:
首先从属性表中选择属性类型为1的记录,并计算每个产品被多少个公司所拥有,将结果作为t1表。然后从t1表中选择拥有至少三个不同公司的产品ID,将结果作为t2表。
接下来从属性表中选择属性类型为1的记录,并将其与t2表进行自然连接操作,得到拥有t2表中产品的属性记录,将结果作为t3表。在t3表中,根据公司ID进行分组,并计算每个公司拥有的属性记录数量和t2表的记录数量,将结果作为t4表。
最后在t4表中,选择属性记录数量等于t2表记录数量的公司,并返回它们的ID。
相关问题
select t1.pro_c_id from ( ( select pro_c_id, count(distinct(pro_pif_id)) as cnt1 from property, finances_product where pro_pif_id = p_id and pro_type = 1 group by pro_c_id ) as t1 join ( select pro_c_id, count(distinct(pro_pif_id)) as cnt2 from property, fund where pro_pif_id = f_id and pro_type = 3 group by pro_c_id ) as t2 on t1.pro_c_id = t2.pro_c_id )
这是一个SQL语句,根据两个子查询的结果,对两个表进行join操作,最终返回pro_c_id,即具有某些属性和基金的公司的ID。具体的查询条件是:
在属性表和finances_product表中,如果属性的p_id等于产品的pro_pif_id,并且属性类型为1,则计算每个公司拥有的不同产品数量,并将结果作为t1表。
在属性表和fund表中,如果属性的f_id等于基金的pro_pif_id,并且属性类型为3,则计算每个公司拥有的不同基金数量,并将结果作为t2表。
最后将t1表和t2表按照pro_c_id进行join操作,并返回pro_c_id。
elect t1.pro_c_id from ( ( select pro_c_id, count(distinct(pro_pif_id)) as cnt1 from property, finances_product where pro_pif_id = p_id and pro_type = 1 group by pro_c_id ) as t1 join ( select pro_c_id, count(distinct(pro_pif_id)) as cnt2 from property, fund where pro_pif_id = f_id and pro_type = 3 group by pro_c_id ) as t2 on t1.pro_c_id = t2.pro_c_id ) where t1.cnt1 > t2.cnt2
这也是一条 SQL 查询语句,它的功能是查询出满足以下条件的商品属性:
1. 属性类型为 1 或 3
2. 属性所属的产品信息分别与 finances_product 表和 fund 表中的记录关联
3. 统计每个商品的不同产品信息数量(对于 pro_type = 1 的属性,统计 pro_pif_id 的个数;对于 pro_type = 3 的属性,统计 f_id 的个数)
4. 比较每个商品在不同类型的产品信息数量,只返回 pro_type = 1 的商品且其对应的 pro_pif_id 数量大于 pro_type = 3 的 f_id 数量。
查询结果是 pro_c_id 列的值。