由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教个面试时遇到的sql 题
相关主题
How to design the sql for this problem? (转载)同时申请h1b和OPT Extension ,打了SEVIS的电话
一道sqlCS 面试题总结(4)
初级SQL问题k-selection algorithm
leetcode Nth Highest Salary 谁做出来了?还有比我更悲的吗
请教SQL面试题帮忙看着HM是不是有问题
HIRING Loan Processor FULL TIME ONLYonsite后被拒,怎么回复对方邮件呢?
facebook的一道题问个sql问题
拿到offer,分享之前的一些onsite面试贴一个google 面题
相关话题的讨论汇总
话题: loan话题: amount话题: loans话题: state话题: decile
进入JobHunting版参与讨论
1 (共1页)
e****0
发帖数: 378
1
take home assignment里的一道。由于我assigment做挂了,所以没机会知道反馈了。
想知道有什么好的写法。
table:
row_id - A unique id for the row
customer_id — A unique id for the loan borrower
loan_amount — The amount of the loan requested by the borrower
addr_state — Borrower's state of residence
问题:
Now let's rank the states by their top decile of loans to see where
customers borrow the most. Find the states where the cutoff for the top 10%
of loans (by loan amount requested) is the highest. If two states have the
same cut-off for the top decile, then please break ties by preferring the
state with the highest number of loans requested. Provide the list of the
top 10 states ranked in this manner as well as the total number of loans
requested in each state and the loan amount cut-off for the top decile of
loans.
多谢大家!
A*******e
发帖数: 2419
2
没看懂问题。有示例么?

%

【在 e****0 的大作中提到】
: take home assignment里的一道。由于我assigment做挂了,所以没机会知道反馈了。
: 想知道有什么好的写法。
: table:
: row_id - A unique id for the row
: customer_id — A unique id for the loan borrower
: loan_amount — The amount of the loan requested by the borrower
: addr_state — Borrower's state of residence
: 问题:
: Now let's rank the states by their top decile of loans to see where
: customers borrow the most. Find the states where the cutoff for the top 10%

n*********u
发帖数: 1030
3
SELECT state, loan_amount
FROM (
SELECT t1.loan_amount, t1.state, t1.rank, t2.ct
FROM (
SELECT loan_amount, state, (CASE state WHEN @currState THEN @rownum:
= @rownum + 1 ELSE @rownum := 1 AND @currState=state END) + 1 as rank, @
ctnum:=@ctnum+1 ac ct
FROM table t, (SELECT @rownum := 0, @currState := '', @ctnum:=0) r
ORDER BY state, loan_amount DESC
) t1 WHERE t1.rank = t1.ct * 0.1
) tt
order by tt.rank, tt.ct DESC
limit 10;
1 (共1页)
进入JobHunting版参与讨论
相关主题
贴一个google 面题请教SQL面试题
Job openings.HIRING Loan Processor FULL TIME ONLY
Bloomberg 电面facebook的一道题
问道 facebook 面试题拿到offer,分享之前的一些onsite面试
How to design the sql for this problem? (转载)同时申请h1b和OPT Extension ,打了SEVIS的电话
一道sqlCS 面试题总结(4)
初级SQL问题k-selection algorithm
leetcode Nth Highest Salary 谁做出来了?还有比我更悲的吗
相关话题的讨论汇总
话题: loan话题: amount话题: loans话题: state话题: decile