Redian新闻
>
请教一个求职面试题:如何写一个SQL query求表中对角线的和
avatar
请教一个求职面试题:如何写一个SQL query求表中对角线的和# Database - 数据库
s*l
1
请教一个求职面试题:如何写一个SQL query求表中对角线的和
avatar
j*n
2
well, it is 43$ value...
http://safari.oreilly.com/1565927567/transqlcook-CHP-3-SECT-16
this is a calculation of a squared matrix trace or sum of its n eigenvalues.
just tell the interviewer go to hell, SQL query is not dedicated to do such
mathematic calculation. there is tons of statistical analysis software can
easily resolve this problem, even you can use C++ do handle it.
at least I am not stupid enough to consider using SQL.
avatar
j*n
3
2nd thought...
this might be using SQL inside SAS.
you may transform this nxn matrix into a data set with 2 columns:
one is a list of all numeric data, another one is the location flag of each
number.
you may flag out each of diagonal data as 'Y', then now you can do it with
simple SELECT with sum().
avatar
B*g
4
其实我真的很无聊,搞了一个user defined function in oracle.
CREATE OR REPLACE FUNCTION CalculateDiagonal(pivTableName IN VARCHAR2)
RETURN NUMBER IS
TYPE ltypColumn IS TABLE OF user_tab_cols%ROWTYPE;
lrecColumn ltypColumn;

TYPE ltypSeqNo IS TABLE OF VARCHAR2(100);
lrecSeqNo ltypSeqNo;
lnTotal NUMBER := 0;
lnTmpTotal NUMBER := 0;
lvSql VARCHAR (1000) := '';
BEGIN
lvSql := 'SELECT * FROM user_tab_cols WHERE table_name = ''' ||
pivTableName || '''';
EXECUTE IMME

【在 s****l 的大作中提到】
: 请教一个求职面试题:如何写一个SQL query求表中对角线的和
avatar
M*r
5
我估计哈,原意是想要一个非常fancy/tricky的SQL Query, 一句搞定 :-)

【在 B*****g 的大作中提到】
: 其实我真的很无聊,搞了一个user defined function in oracle.
: CREATE OR REPLACE FUNCTION CalculateDiagonal(pivTableName IN VARCHAR2)
: RETURN NUMBER IS
: TYPE ltypColumn IS TABLE OF user_tab_cols%ROWTYPE;
: lrecColumn ltypColumn;
:
: TYPE ltypSeqNo IS TABLE OF VARCHAR2(100);
: lrecSeqNo ltypSeqNo;
: lnTotal NUMBER := 0;
: lnTmpTotal NUMBER := 0;

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。