文章详情

专注互联网科技,赋能企业数字化发展

rank() dense_rank() row_number()

作者:rank() dense_rank() row_number()

What's the difference between RANK(), DENSE_RANK(), and ROW_NUMBER()? - RANK() looks like this: 1,1,3,4,5 - DENSE_RANK() looks like this: 1,1,2,3,4 - ROW_NUMBER() looks like this: 1,2,3,4,5 Don't try to memorize these sequences of numbers! Here's what to focus on instead: the difference between these is the way they break ties. 1. RANK() - when there's a tie, repeat the rank. Skip numbers. 2. DENSE_RANK() - when there's a tie, repeat the rank. Never skip numbers. (This makes it "dense"). 3. ROW_NUMBER() - when there's a tie, do not repeat. Never skip numbers. Break the tie by randomly picking a "winner." A picture is worth a thousand words, so check out the image below to see a code snippet you can actually run in BigQuery to test this out! Btw, I use row_number() = 1 to remove the duplicated column I want all the time. #Sql #数据分析 #sql语句 #rank #数据分析求职 #北美留学生求职 #留学生求职 #data求职#英专生就业

返回新闻列表