由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - interview question (SQL)
相关主题
请教一个SQL问题mysql 问题 (转载)
请教SQL server的一个programming的问题,谢谢急请教sql server while loop memory 问题
Question for SQL statment抱怨一下 数据库 里头的一些不严谨。
how to see all the tables in SQL*PLUS?初级问题
Can I create thousands table in one...SQL Server stupid questions
急问一个关于T-SQL的问题,谢谢Oracle 问 题 请 诸 位 大 侠 指 教, 急 急 急!!!
SQL combine two columns from two different tables no shared (转载)How to get schema?
请教SQLHow to insert images into tables?
相关话题的讨论汇总
话题: table话题: sql话题: double话题: sqr
进入Database版参与讨论
1 (共1页)
H*M
发帖数: 1268
1
write in ANSI SQL only.
you are given two tables:
Table A:
IDA(int) x(double) y(double) correlatedIDB(int)
1 1.0 2.0
2 2.1 3.3
Table B:
IDB(int) x(double) y(double)
1 1.1 2.1
2 2 3
3 10 15
find the cloest ID in table B for each row in A and update the value in Tabl
e A.
by closest, it means min(sqr(A.x-B.x) + sqr(A.y-B.y)).
Therefore,
The correlatedIDB of the first row in Table A should be 1
The correla
a9
发帖数: 21638
2
cursor算不算ansi sql里的?

Tabl

【在 H*M 的大作中提到】
: write in ANSI SQL only.
: you are given two tables:
: Table A:
: IDA(int) x(double) y(double) correlatedIDB(int)
: 1 1.0 2.0
: 2 2.1 3.3
: Table B:
: IDB(int) x(double) y(double)
: 1 1.1 2.1
: 2 2 3

a9
发帖数: 21638
3
看看这个行不?
update a set a.correlatedidb=d.minres from a left join (
select aid,min(res) minres from
(select a.id aid,b.id bid,min(sqr(a.x-b.x)+sql(a.y-b.y)) res from a cross
join b) c
group by aid) d on a.id=d.aid

Tabl

【在 H*M 的大作中提到】
: write in ANSI SQL only.
: you are given two tables:
: Table A:
: IDA(int) x(double) y(double) correlatedIDB(int)
: 1 1.0 2.0
: 2 2.1 3.3
: Table B:
: IDB(int) x(double) y(double)
: 1 1.1 2.1
: 2 2 3

1 (共1页)
进入Database版参与讨论
相关主题
How to insert images into tables?Can I create thousands table in one...
how to separate the table急问一个关于T-SQL的问题,谢谢
how to particially delete record in sql serverSQL combine two columns from two different tables no shared (转载)
如何用SQL语句判断一个TABLE是否存在?请教SQL
请教一个SQL问题mysql 问题 (转载)
请教SQL server的一个programming的问题,谢谢急请教sql server while loop memory 问题
Question for SQL statment抱怨一下 数据库 里头的一些不严谨。
how to see all the tables in SQL*PLUS?初级问题
相关话题的讨论汇总
话题: table话题: sql话题: double话题: sqr