select a.c3 from (select c2,c3 from a where c1=1) a where a.c2 in (select c2,c3 from a where c1=2) b
解决方案 »
- 人才招聘程序,做筛选,求达人给一个SQL语句思路。我可能把问题想复杂了,迷茫了
- sql 2000 连接 sql 2008
- 如何用sql在已有表中,新创建一列
- 完全备份和直接复制.MDF和.LDF有区别吗
- 请问如何用脚本将access中的数据导入到sqlserver中
- ms sql 2000备份恢复到ms sql2008时提示出错
- 讲一下join和union的用法,我怎么感觉两个有点象呢
- 如何得到一个数据库对象的SQL脚本?
- 备份和恢复sql数据库的语句是什么?高分求教!
- 用InstallShield制作前Delphi后Sybase的安装文件的BDE问题
- 主题:在WIN2000下安装D版SQL SERVER 7.0的成功标准是什么?
- 请问哪有foxbase2.1+下载
select b.c3 from (select c2,c3 from a where c1=1) b where b.c2 in (select c2,c3 from a where c1=2)
FROM
(select column1,column2,column3 from table1 where column1=1) A,(select column1,column2,column3 from table1 where column1=2) B
WHERE A.column2=B.column2
对于guo的语句:
我想可能是忽略了其实s3并不是s1中的某一部分或s2的某一部分,而guo的语句显然只是s1中的一部分,反过来讲,将sql语句换成:
select b.c3 from (select c2,c3 from a where c1=2) b where b.c2 in (select c2,c3 from a where c1=1)
其结果集就不一样了。
而DeD的语句,我想是不是应该这样:
SELECT A.column3,b.column3
FROM
(select column1,column2,column3 from table1 where column1=1) A,(select column1,column2,column3 from table1 where column1=2) B
WHERE A.column2=B.column2 我不敢确定,请大家讨论。
select a.*
from (select * from tab1 where col1='1') a, (select * from tab1 where col1='2') b where a.col2=b.col2 and a.col3=b.col3
select a.*
from (select * from tab1 where col1='1') a, (select * from tab1 where col1='2') b where a.col2=b.col2 and a.col3=b.col3
1.column1=1时的集合s1
2.column1=2时的集合s2
则
3.求当s1和s2的column2相等时的交集s3 -->> 空集
1 2 9
2 3 7
2 2 20那你要返回哪一个值呢?
9,还是20,还是两个都要?
可能是我没说清楚,并不是s1和s2的交集,
而是s1和s2的column2相等时的集合s3,不好意思啊。
答案应该是:
SELECT A.column3,b.column3
FROM
(select column1,column2,column3 from table1 where column1=1) A,(select column1,column2,column3 from table1 where column1=2) B
WHERE A.column2=B.column2