由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - correlated subquery
相关主题
紧急求助, 关于SQL Server咋样选一个表中在另一个表中不含有的记录
[转载] Can anyone interpret this simple SQL?Remove duplicate from oracle table
About INSERT IGNORE新手问个简单的SELECT问题
问一个SQL Server的问题Oracle新手请教一个问题
请问那种很复杂的sql语句,有什么套路吗?How to get other columns after UNION?
correlated subquery怎么初始化大表?
MS T-SQL 问题ADO & DAO &SQL...Help...
better solution for cross table query in sql?求助:sql server 2000, 这句话怎么写?
相关话题的讨论汇总
话题: department话题: select话题: where话题: t1话题: char
进入Database版参与讨论
1 (共1页)
m*****h
发帖数: 18
1
CREATE TABLE department(
dept_no CHAR(4) NOT NULL,
dept_name CHAR(25) NOT NULL,
location CHAR(30) NULL)
insert into department values ('d1', 'developer', 'Dallas')
insert into department values ('d2', 'tester', 'Seattle')
insert into department values ('d3', 'marketing', 'Dallas')
SELECT t1.*
FROM department t1
WHERE t1.location IN
(SELECT t2.location
FROM department t2
WHERE t1.dept_no <> t2.dept_no)
dept_no dept_name location
B*****g
发帖数: 34098
2
咱们每一个record都看一下。
d1: sql就变成
SELECT t1.*
FROM department t1
WHERE t1.dept_no = 'd1'
AND t1.location IN
(SELECT t2.location
FROM department t2
WHERE 'd1' <> t2.dept_no)
也就是
SELECT t1.*
FROM department t1
WHERE t1.dept_no = 'd1'
AND t1.location IN ('Dallas', 'Seattle')
所以符合, d1有了
d2: sql就变成
SELECT t1.*
FROM department t1
WHERE t1.dept_no = 'd2'
AND t1.location IN
(SELECT t2.location
FROM department t2
WHERE 'd2' <> t2.dept_no)
也就是
SELECT t1.*
FROM department t1
WHERE t1.dept_no = 'd2'
AND t

【在 m*****h 的大作中提到】
: CREATE TABLE department(
: dept_no CHAR(4) NOT NULL,
: dept_name CHAR(25) NOT NULL,
: location CHAR(30) NULL)
: insert into department values ('d1', 'developer', 'Dallas')
: insert into department values ('d2', 'tester', 'Seattle')
: insert into department values ('d3', 'marketing', 'Dallas')
: SELECT t1.*
: FROM department t1
: WHERE t1.location IN

1 (共1页)
进入Database版参与讨论
相关主题
求助:sql server 2000, 这句话怎么写?请问那种很复杂的sql语句,有什么套路吗?
帮忙解释下这个查询,有关NULL的correlated subquery
Merge table with one single query?MS T-SQL 问题
SQL Conditional Selectbetter solution for cross table query in sql?
紧急求助, 关于SQL Server咋样选一个表中在另一个表中不含有的记录
[转载] Can anyone interpret this simple SQL?Remove duplicate from oracle table
About INSERT IGNORE新手问个简单的SELECT问题
问一个SQL Server的问题Oracle新手请教一个问题
相关话题的讨论汇总
话题: department话题: select话题: where话题: t1话题: char