postgresql 有一组数据 我想得到如下效果

[复制链接]
查看11 | 回复3 | 2013-7-3 15:38:34 | 显示全部楼层 |阅读模式
暂时用 SQL Server 来模拟了一下。应该可以的。CREATE TABLE #temp (f_idINT,p_idINT);INSERT INTO #temp VALUES(2,1);INSERT INTO #temp VALUES(14,1);INSERT INTO #temp VALUES(16,1);INSERT INTO #temp VALUES(2,2);INSERT INTO #temp VALUES(14,2);INSERT INTO #temp VALUES(2,3);INSERT INTO #temp VALUES(15,3);1.想找到f_id =2 并且还 =14 还 =16 的数据 , 也就是 pid=...
回复

使用道具 举报

千问 | 2013-7-3 15:38:34 | 显示全部楼层
什么意思?f_id =2 并且还 =14 还 =16 的数据:select * from tab_a where f_id in (2,14,16) 找f_id = 2 还=14的,也就是p_id = 1,2:select * from tab_a where f_id in (2,14) 找f_id = 2的 也就是p_id =...
回复

使用道具 举报

千问 | 2013-7-3 15:38:34 | 显示全部楼层
select * from table where p_id=1;select * from table where (f_id in (select f_id from table where p_id=1)) and (f_id in (select p_id from table where p_id=2));select * from table...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行