第1个回答 2013-06-15
如果要详单
select * from prod_info a where exists(select 1
from prod_info where a.cust_id = cust_id and prod_id = '01') and
exists(select 1 from prod_info where a.cust_id = cust_id and prod_id =
'02')
如果只要户ID
select cust_id from prod_info a where exists(select 1 from prod_info where a.cust_id = cust_id and prod_id = '01') and exists(select 1 from prod_info where a.cust_id = cust_id and prod_id = '02') group by cust_id本回答被网友采纳
第2个回答 2013-06-15
应该是and:select * from prod_info where prod_id = 01 and prod_id = 02
不过这也不对,给你写个伪代码吧,
select * from
(
select * from prod_info where prod_id = 01 as a
join
select * from prod_info where prod_id = 02 as b
)
where a.cust_id = b.cust_id
order by cust_id
大概这意思吧
不过题外话,感觉表设计的有问题啊,既然是prod_info,那key是什么呢?
起码肯定不是 cust_id和prod_id
而且感觉你所提的prod_id应改为prod_class_id吧?
可以就采纳吧
第3个回答 2013-06-14
那你就查prod_info里面prod_id是基金产品和保险产品的记录即可:select * from prod_info where prod_id = 01 or prod_id = 02这是最简单的写法,如果要优化的话还可以有另外方法,这个自己去了解一下吧。
第4个回答 2013-06-14
WITH CTE
AS(
SELECT cust_id,
prod_id,
ROW_NUMBER() OVER(PARTITION BY cust_id ORDER BY cust_id) OD
FROM prod_info
)
SELECT cust_id,
prod_id
FROM CTE
WHERE OD =2