12305是什么电话| 代谢不好吃什么药| 视黄醇结合蛋白是什么| 双氧水又叫什么名字| 什么样的梦才算是胎梦| 身份证后面有个x是什么意思| 淋巴结增大是什么原因严重吗| 心率低有什么症状| 修为是什么意思| 阴茎皮开裂是什么原因| 地级市市委书记是什么级别| 打喷嚏是什么预兆| 梦见红棺材是什么征兆| gold是什么意思| 月经第二天属于什么期| 吃什么才能减肥最快| 1938年中国发生了什么| 大便有点绿色是什么原因| 太瘦的人吃什么能长胖| 桃不能和什么一起吃| 肺结核是什么原因引起的| dp是什么意思| 命犯桃花是什么意思| 维生素b族什么时候吃最好| 命门火衰是什么意思| 为什么经常流鼻血| 扁桃和芒果有什么区别| 噬是什么意思| 福建人喜欢吃什么口味| 大悲咒什么意思| 皮下囊肿是什么原因引起的| 初恋是什么| 脂蛋白a高是什么原因| 干什么一天能挣1000元| 什么防晒霜好用| 龟头炎的症状是什么样| 苹果手机为什么充不进去电| 梦到门坏了是什么意思| 216是什么意思| 闲聊是什么意思| 8月26日是什么星座| 赵子龙属什么生肖| hp感染是什么病| 梦到蛇是什么预兆| 蒙氏教育是什么| 眼皮红肿是什么原因| 迅雷不及掩耳之势是什么意思| 金刚是什么意思| 唾液酸苷酶阳性是什么意思| 方得始终什么意思| 千岛酱是什么味道| 什么是制动| 妈妈的奶奶应该叫什么| 十二生肖排第一是什么生肖| 手心发痒是什么原因| 月办念什么| 什么虫子咬了会起水泡| 肋骨下面疼是什么原因| 什么平稳| 痞满是什么意思| 脾是什么| 小孩子长白头发是什么原因| 1.15是什么星座| 老虎头是什么牌子衣服| 腰间盘突出吃什么药| 吃什么可以去脂肪肝| 大豆是什么| mrsa是什么细菌| 狗咬人后狗为什么会死| 精益求精的意思是什么| b是什么单位| 脊柱疼是什么原因| 什么叫牙周炎| 鸡胗是鸡的什么部位| 羊水是什么味道| 12.29是什么星座| 花字五行属什么| 煮玉米放什么好吃| 碳酸盐质玉是什么玉| 黄桃什么时候成熟| 易岗易薪是什么意思| 乳腺增生吃什么食物好| 紫癜吃什么好得快| 什么是ph值| 莫逆是什么意思| 超敏c反应蛋白高是什么意思| 耳石症什么症状| 什么是大三阳| 人是由什么组成的| 阴囊是什么部位| 裹小脚是什么时候开始的| 警察为什么叫条子| 西安古时候叫什么| 28年属什么生肖| 蛇遇猪就得哭什么意思| 子夜是指什么时间| 手指关节疼痛吃什么药| 有张有弛是什么意思| 九眼天珠是什么做的| 本科专科有什么区别| 心脏看什么科室| 酸儿辣女什么意思| 公立医院和私立医院有什么区别| 门槛费是什么意思| 孩子咽炎老是清嗓子吃什么药| 表示什么意思| 尿糖弱阳性是什么意思| 吃什么安神有助于睡眠| 欣字取名什么寓意| 气管小憩室是什么意思| 小孩子消化不好吃什么调理| 菜肴是什么意思| 口臭什么原因| 小孩出冷汗是什么原因| 全科门诊主要看什么| 心脏增大吃什么药| 少叙痣是什么意思| 心率过缓吃什么药| 异常子宫出血是什么原因| 老来得子是什么意思| 牙龈炎吃什么药| 一个丝一个鸟读什么| 白喉是什么意思| 胃疼去医院挂什么科| 鹿晗的粉丝名叫什么| 阿胶配什么吃不上火| 印堂发红是什么的征兆| 什么叫肠上皮化生| hpv男性有什么症状| 男人为什么好色| 天热喝什么茶好| 久视伤血是什么意思| 什么机油好| 器质性心脏病是什么意思| 小雪时节吃什么| 什么情况下怀疑白血病| 梦见一个人代表什么| 月经前腰疼是什么原因| 代沟是什么意思| 送男朋友什么礼物合适| 经常上火口腔溃疡是什么原因| 刀模是什么| 医生和医师有什么区别| 拍胸片挂什么科室| 上呼吸道感染吃什么药| 梦见栽树是什么预兆| 晔字为什么不能取名| 住院带什么必备物品| 为什么一个月来两次姨妈| 鬓角长痘痘是什么原因| 体检挂什么科室| 糖异生是什么意思| 艾滋病通过什么传染| 三唑磷主要打什么虫| kids是什么牌子| 清酒是什么酒| 核磁dwi是什么意思| 83年猪是什么命| 什么玩意儿| 输尿管不扩张什么意思| 三阳开泰是什么生肖| 咦惹是什么意思| 小孩荨麻疹吃什么药| 眩晕看什么科| 什么家庭养出自私冷漠| 玉米有什么营养价值| 吃什么可以生发| 同房是什么| 艾草治什么病| 外强中干是什么意思| 男人喝什么汤补肾壮阳| 宫颈癌前期有什么症状| 感冒吃什么饭菜比较好| 叶酸有什么作用| 家族史是什么意思| 寄生茶在什么树上最好| 1月30日什么星座| 喝雄黄酒是什么节日| 很的右边读什么| 直肠肿瘤不能吃什么| 张家界地貌属于什么地貌| 氯是什么| 毛泽东的女儿为什么姓李| 什么的问题| 乐哉是什么意思| 一什么鹿角| 夜宵吃什么不会胖| 什么叫犹太人| 什么水果含硒量最高| 鼻窦炎是什么原因引起的呢| 手指起倒刺是什么原因| 切尔斯什么意思| 红糖水什么时候喝| 手爱出汗是什么原因| 9月16号是什么星座| 不以为然是什么意思| sn是什么| 生殖细胞瘤是什么病| 什么能力| 什么食物蛋白质含量高| 梦见摘丝瓜有什么预兆| 先入为主是什么意思| 6月20号什么星座| 什么是分子| 美团是干什么的| paris是什么牌子| 志愿号是什么意思| 凶宅是什么意思| 仪态什么什么| 舌苔厚白是什么原因| 血象高是什么原因| 香蕉和什么一起吃能减肥| 老有眼屎是什么原因| 路程等于什么| 江西老表是什么意思| 鹿晗的原名是什么| 米老鼠叫什么名字| 无期是什么意思| 玻璃水是干什么用的| 激素药是什么意思| 连号的钱为什么不能花| 甲亢能吃什么| 二聚体偏高是什么原因| 叶凡为什么找石昊求救| 莆田医院是什么意思| 肚脐下方疼是什么原因| 一个均一个金念什么| 什么首阔步| 有狐臭是什么原因| 能戒烟的男人什么性格| rad是什么意思| 寻麻疹看什么科| 现在有什么好的创业项目| 免疫性疾病是什么意思| 梦见生孩子是什么意思| 欧多桑是什么意思| 黄皮肤适合什么颜色的衣服| 人心果什么时候成熟| 山茶花什么时候开| 探索是什么意思| 175是什么尺码| 睡眠质量差吃什么药| 丘比特是什么意思| 金风玉露是什么意思| 什么的大自然| 丁未年五行属什么| 水黄是什么原因| 12月8号是什么星座| 早泄要吃什么药| 鱿鱼是什么动物| 发量多的女生适合什么发型| 五脏六腑指什么| 地中海是什么意思| 双插头是什么意思| 慧命是什么意思| 阴茎不硬吃什么药| 巾帼是指什么| TPS什么意思| 梦见自己假牙掉了是什么意思| 什么痣不能点| 过肺是什么意思| 什么是机制| 月经期间适合吃什么食物| 羊水透声欠佳什么意思| 百度
 
KDnuggets Top Blog Winner

房车与露营 寰球速览 第七十九期-最新行业动态

百度 但在邪念驱使下,五人前去偷窥女浴室,作为惩罚,被管理著学园纪律的「里学生会」投入了惩罚大楼,他们还会有明日的希望吗?作品除了改编动画、日剧外,也在近期即将推出改编舞台剧。

Focusing on the important concepts for data scientists.



Top Five SQL Window Functions You Should Know For Data Science Interviews
 

SQL is the universal language in the data world and is the most important skill to nail down as a data professional.

The reason SQL is so important is that it is the main skill that is required during the data wrangling phase. A lot of data exploration, data manipulation, pipeline development, and dashboard creation is done through SQL.

What separates great data scientists from?good data scientists is that great data scientists can wrangle data as much as the capabilities of SQL allow.?A big part of being able to fully use all that SQL has to offer is by knowing how to use window functions.

With that said, let’s dive into it!

 

1. Deltas with LEAD() and LAG()

 
LEAD() and LAG() are mostly used when comparing one period of time with the previous period of time for a given metric. To give a few examples...

  • You can get the delta between each year’s sales and the previous year’s sales
  • You can get the delta in the number of sign-ups/conversions/website visits on a month to month basis
  • You can compare user churn on a monthly basis

Example:

The following query shows how you can query the monthly percent change in costs

with monthly_costs as (
    SELECT
        date
      , monthlycosts
      , LEAD(monthlycosts) OVER (ORDER BY date) as
        previousCosts
    FROM
        costs
)SELECT
    date
  , (monthlycosts - previousCosts) / previousCosts * 100 AS
    costPercentChange
FROM monthly_costs

 

2. Cumulative Sums with SUM() or COUNT()

 
Calculating running totals can be simply done through a windows function that starts with SUM() or COUNT(). This is a powerful tool when you want to show the growth of a particular metric over time. More specifically, it’s useful in the following circumstances:

  • Get a running total of revenue and costs over time
  • Get a running total of time-spent-on-app per user
  • Get a running total of conversions over time

Example:

The following example shows how you can include a cumulative sum column of monthly costs:

SELECT
    date
  , monthlycosts
  , SUM(monthlycosts) OVER (ORDER BY date) as cumCosts
FROM
    cost_table

 

3. Moving Averages with AVG()

 
AVG() is really powerful in windows functions as it allows you to compute?moving averages?over time.

Moving averages are a simple, yet effective, way to forecast values in the short term. They’re also extremely useful at smoothing out volatile curves on a graph. Generally, moving averages are used to gauge the general direction of where things are moving.

More specifically...

  • They can be used to get the general trend of weekly sales (is the average going up over time?). This would indicate growth as a company.
  • They can likewise be used to get the general trend of weekly conversions or website visits.

Example:

The following query is an example of getting the 10-day moving average for conversions.

SELECT
    Date
  , dailyConversions
  , AVG(dailyConversions) OVER (ORDER BY Date ROWS 10 PRECEDING) AS
    10_dayMovingAverage
FROM
    conversions

 

4. ROW_NUMBER()

 
ROW_NUMBER() is particularly useful when you want to get the first or last record. For example, if you have a table of when gym members came to the gym and you want to get the date of the first day that they came to the gym, you can PARTITION BY customer (name/id) and ORDER BY purchase date. Then, in order to get the first row, you can simply filter for the rows with rowNumber equal to one.

Example:

This example shows how you can use ROW_NUMBER() to get the first date of when each member (user) visited.

with numbered_visits as (
    SELECT
        memberId
      , visitDate
      , ROW_NUMBER() OVER (PARTITION BY customerId ORDER BY
        purchaseDate) as rowNumber
    FROM
        gym_visits
)SELECT
    *
FROM
    numbered_visits
WHERE 
    rowNumber = 1

 

To recap, if you ever need to get the first or last record, ROW_NUMBER() is a great way to achieve that.

 

5. Record Ranking with DENSE_RANK()

 
DENSE_RANK() is similar to ROW_NUMBER() except that it returns the same rank for equal values. Dense ranking is quite useful when it comes to retrieving the top records, for example:

  • If you want to pull the top 10 most-watched Netflix shows this week
  • If you want to get the top 100 users based on dollars spent
  • If you want to see the behavior of the 1000 least active users

Example:

If you wanted to rank your top customers by total sales, DENSE_RANK() would be an appropriate function to use.

SELECT
    customerId
  , totalSales
  , DENSE_RANK() OVER (ORDER BY totalSales DESC) as rank
FROM
    customers

 

Thanks for Reading!

 
And that’s all! I hope that this helps you in your interview prep — I’m sure that if you know these 5 concepts inside-out, you’ll do great when it comes to most SQL window function problems out there.

As always, I wish you the best in your learning endeavors!

 
 
Terence Shin is a data enthusiast with 3+ years of experience in SQL and 2+ years of experience in Python, and a blogger on Towards Data Science and KDnuggets.

Original. Reposted with permission.
 



吃石斛有什么作用 头皮屑特别多是什么原因 窦房结内游走性心律是什么意思 10月13是什么星座 膝盖缝里面疼什么原因
扁桃体肥大吃什么药好得快 4月3号什么星座 补气是什么意思 排卵期是在什么时候 别出心裁的裁是什么意思
拉不出来屎是什么原因 什么叫补充公积金 结婚10周年是什么婚 母后是什么意思 吃什么降血脂最快
桑叶泡水喝有什么功效和作用 火鸡面为什么叫火鸡面 送百合花代表什么意思 土色是什么颜色 黄油是什么
验尿细菌高是什么原因hcv7jop7ns3r.cn 什么色什么流onlinewuye.com 什么是疤痕体质hcv9jop8ns2r.cn 女性安全期是什么时候hcv8jop7ns9r.cn 拉绿屎是什么原因hcv8jop3ns6r.cn
胆固醇高不能吃什么hcv8jop7ns6r.cn 降压药有什么副作用hcv9jop5ns3r.cn 脾胃虚寒是什么症状hcv8jop4ns3r.cn 夏威夷披萨都有什么配料hcv8jop2ns9r.cn 开柙出虎是什么意思sanhestory.com
什么是钙化灶hcv8jop8ns5r.cn 梦到手机丢了什么预兆hcv8jop4ns1r.cn 芭乐什么味道qingzhougame.com 探花是什么意思hcv7jop7ns3r.cn 肾结石能吃什么hcv8jop1ns1r.cn
什么眉什么目hcv9jop5ns4r.cn 心肌缺血有什么症状和表现hcv9jop2ns4r.cn 过午不食是什么意思bjcbxg.com 空洞是什么意思hcv7jop9ns0r.cn 暗物质和暗能量是什么hcv8jop8ns6r.cn
百度