- Given a reimbursement table, make the following data requirements corresponding SQL implementation
- Title: seek reimbursement of all the details sorted obtain reimbursement of the times is a personal reimbursement of how many times, how many times topN the reimbursement of all claims came in time?
- Answer:
- Data table, the table name is analysis_daily_expense, to intermediate "\ t" of the partition
工号(workno) 姓名(name) 报销项(item) 费用(cost) 时间(orderdate)
t001 张一 水费 100 2017-06-01 09:00:00
t002 张二 团建 500 2017-07-02 09:00:00
t003 张三 市场 1700 2017-08-01 09:00:00
t004 张四 维修 150 2017-08-11 09:00:00
t005 张五 出差 800 2017-08-21 11:00:00
t005 张五 市场 1000 2017-09-29 11:00:00
t005 张五 福利 300 2017-09-29 11:00:00
t004 张四 市场 300 2018-01-05 11:00:00
t004 张四 市场 550 2018-01-06 09:00:00
t003 张三 维修 90 2018-02-01 09:00:00
t002 张二 电费 200 2018-02-05 09:00:00
t002 张二 团建 300 2018-02-08 15:00:00
t005 张五 市场 1280 2018-03-07 15:00:00
t005 张五 市场 2280 2018-04-07 15:00:00
t002 张二 维修 230 2018-04-01 15:00:00
t004 张四 福利 200 2018-04-28 15:00:00
t004 张四 福利 1000 2017-12-30 15:00:00
t004 张四 福利 10000 2018-02-13 15:00:00
- sql realization
//重点考查row_number,rank,dense_rank数据排序使用
select workno,name,cost,orderdatetime,row_number() over(partition by name order by orderdatetime asc) as person,rank() over(order by orderdatetime asc) as topN_1, dense_rank() over(order by orderdatetime asc) as topN_2from analysis_daily_expense;
- Demonstration effect
Dawn education is engaged in big data cloud computing, artificial intelligence, education and training, product development, consulting services, talent preferably integrated Internet technology companies.
Founded by a group of front-line Internet BAT, IT elite,
with "happy work, serious life, to build IT vocational education banner" for the vision, the vision of "Let the world not difficult to find work," the mission,
adhere to the "customer first , integrity, passion, embrace change "values,
dedication to students energized and efficiency, practice techniques to change the fate of early heart.
More study and discussion, please join
the official - dawn big data exchange -366,784,928
group of two-dimensional code:
official - dawn web front-end exchange -972,788,995
group of two-dimensional code:
Welcome concern dawn to educate the public number, big data and technical information courses, recruitment and employment trends, educational information dynamic, entrepreneurial history to share a one-stop-sharing, public official micro-channel two-dimensional code number:
Dawn big education official data group 318,971,238,
dawn education official web front group 318,971,238,
reptiles, nlp techniques qq group 320 349 384
hadoop Hive & the Spark & Technology Group 297 585 251
Education and Training's official website: http://myhope365.com
project development business still cloud technology official website: http://shangyuninfo.com/
dawn open class education - from white marble to remember the big brother - the full range of video address: http://myhope365.com/news/index?id=66
dawn cloud classroom applet version, micro-channel sweep The following figure code directly into learning! ! !