职业资格证书有什么用| 胃消化不好吃什么调理| 第一次世界大战是什么时候| 老气横秋是什么意思| 淋巴结肿大用什么药| 真菌涂片检查是查什么| 有胃病的人吃什么最养胃| 金融bp是什么意思| 白芨有什么作用和功效| 妈妈生日送什么礼物| 什么是低密度脂蛋白| 榴莲吃多了有什么危害| 遗忘的遗是什么意思| 不悔梦归处只恨太匆匆是什么意思| 口粮是什么意思| 嘴巴苦苦的是什么原因| 鸡炖什么好吃又有营养| 一个马一个并念什么| 牙髓炎是什么原因引起的| 相濡以沫是什么生肖| 血少一撇念什么| 飓风什么意思| mas是什么意思| 孕期什么时候补铁| 木薯是什么| 淘米水洗脸有什么好处| 两拐是什么军衔| 青出于蓝是什么意思| 乳房胀痛吃什么药| 吃什么解腻| 大枣吃多了有什么危害| 疏离感是什么意思| 低烧吃什么药最好| 舌苔发白是什么症状| 胆囊壁结晶是什么意思| 色达在四川什么地方| 梦见别人搬家预示什么| 胰岛素有什么副作用| 肝火旺盛吃什么药效果最好| 如果怀孕了会有什么预兆| 鸟死在家里是什么征兆| no是什么气体| 手为什么会抖| 圣贤是什么意思| 大便白色是什么原因| 谷丙转氨酶偏高吃什么药| 甲流是什么病| 医政科是做什么的| 吃梨有什么好处| 血小板分布宽度偏高是什么意思| 皮肤过敏用什么药最好| 遣返回国有什么后果| 牛肉炒什么好吃| 绾色是什么颜色| 补肾吃什么东西效果最好| 鳞状上皮内低度病变是什么意思| 抗0是什么意思| 三个小是什么字| 手指甲凹凸不平是什么原因| 胆汁酸高吃什么药| 阿斯巴甜是什么东西| 白化病是什么病| 嗓子痒干咳吃什么药| 吃什么油最健康排行榜| 印模是什么意思| 驰骋沙场百战威是什么生肖| 浣熊吃什么食物| 为什么叫夺命大乌苏| 小分子肽有什么作用| 胰腺癌有什么症状| 类风湿要吃什么药| 嘴角裂口是什么原因怎么办| 157是什么意思| 受精卵着床有什么反应| 什么的寒风| 狗狗发抖是什么原因| 胆汁反流是什么原因| 穿什么内衣好| 尿频尿急尿不尽吃什么药最快见效| 为什么会有耳石症| 20点是什么时辰| 南辕北辙的意思是什么| 裘皮是什么皮| pioneer是什么牌子| 酱瓜是什么瓜| 鱼上浮的原因是什么| 阑尾炎是什么症状| 一个虫一个夫念什么| 什么东西泡水喝降血压| 血常规红细胞偏高是什么原因| 破处是什么感觉| 产后大出血一般发生在什么时候| 囡是什么意思| 中将是什么级别| 梦见自己得了重病预示什么| 痛风吃什么药止痛最快| 让您费心了是什么意思| 梦到别人怀孕了是什么意思| 健康证都检查什么项目| 中秋节送什么好| 办护照有什么要求| skll什么牌子| 肠易激综合症吃什么药| 耳鼻喉科属于什么科| 1978年五行属什么| 猪狗不如是什么意思| 岁月静好什么意思| 点痣不能吃什么东西| 有什么故事| 吃什么化痰| 油粘米是什么米| 啤酒加味精有什么作用| 便秘用什么| 蛐蛐进屋有什么预兆| 什么除草剂三年不长草| 张五行属性是什么| 身体不适是什么意思| 葡萄胎有什么症状反应| 9月20日是什么星座| 翻什么覆什么| 气血不足补什么| ssr是什么意思| 天克地冲是什么意思| pgr是什么意思| 月牙是什么| earth是什么意思| 牙龈痛吃什么药| 为什么会长囊肿| 喝了蜂蜜水不能吃什么| 肾病吃什么药最好| 吃鹅蛋对孕妇有什么好处| 健康证照片用什么底色| 公务员属于什么行业| 西天取经是什么意思| t是什么| 什么的白桦| 为什么要长智齿| 萨德是什么意思| 为什么要多吃鱼| 心脑血管挂什么科| 笔记本电脑什么品牌好| cd是什么意思啊| 男人小腹疼痛是什么原因| 夏至是什么时候| 缺铁吃什么药| 失聪是什么意思| 破釜沉舟是什么意思| 范仲淹号什么| 人中浅的女人代表什么| 石榴叶子泡水喝有什么功效| 莯字五行属什么| 肛门痒什么原因| 热火朝天是什么意思| 炮制是什么意思| 巨蟹什么象星座| 椎管狭窄吃什么药| 甘油三脂高是什么意思| 死是什么感觉| 灰指甲什么样| 内分泌科属于什么科| 邮戳是什么意思| 什么是肛漏| 颠勺是什么意思| 孕早期头晕是什么原因| 鼠妇吃什么| 什么持不什么| 外阴过敏用什么药| 蒲公英有什么功效和作用| 脑梗用什么药| 规格是什么意思| 女人小便疼是什么原因| 天妒英才是什么意思| 大腿后侧疼痛什么原因| 小工是什么意思| 腺样体面容是什么意思| 神经内科看什么病| 什么水晶招财旺事业| 脂肪肝能吃什么水果| 屁股长痘痘是什么原因| 贾宝玉和林黛玉是什么关系| 铁蛋白低是什么原因| 义愤填膺是什么意思| 旬空是什么意思| 一什么绳子| 属龙女和什么属相最配| 中筋面粉适合做什么| 什么是理想| 苯三酚注射有什么用| 甲亢看什么科| 男人早泄吃什么药| 7月17是什么星座| 滴水不漏是什么生肖| 溢脂性皮炎用什么药| 口若悬河是指什么生肖| 输卵管堵塞有什么样症状| hdl是什么意思| 花重锦官城的重是什么意思| 什么人容易得圆锥角膜| 晚上7点到9点是什么时辰| 99年是什么年| 蹀愫女鞋什么档次| 哏是什么意思| jvc是什么牌子| 褥疮是什么| 喉咙有痰咳嗽是什么原因| 粉玫瑰适合送什么人| 女子与小人难养也什么意思| 月子可以吃什么菜| 什么是oa| 经常腰疼是什么原因女| moo是什么意思| 男人右眉毛里有痣代表什么| mr是什么检查项目| butterfly是什么意思| 等闲识得东风面下一句是什么| 红玫瑰花语是什么意思| 男人得了hpv有什么症状| 李子树苗什么品种好| 孕妇什么不能吃| 什么地方能做亲子鉴定| 开口腔诊所需要什么条件| 党参长什么样子| 脸上长痘痘是什么原因引起的| 半夜醒来睡不着是什么原因| 幽门螺杆菌用什么药| 人体消化道中最长的器官是什么| 燥热是什么意思| 蜂蜜有什么作用与功效| 寸头适合什么脸型| pick什么意思| 2月什么星座| 发烧白细胞高是什么原因| 阿玛尼手表属于什么档次| 为什么学习不好| 尿道感染用什么消炎药| 梦见麒麟是什么兆头| 除体内湿热最好的中成药是什么| 球镜是什么意思| 黄褐斑内调吃什么中药| 冬天怕冷夏天怕热是什么体质| 看乳房挂什么科| 蜈蚣怕什么东西| national是什么牌子| 什么牌子手机好| 病理科是干什么的| 鹿晗的原名是什么| 葡萄糖偏高有什么问题| 噗噗噗是什么意思| 胃窦糜烂是什么意思严重吗| 一直打喷嚏是什么原因| 空前绝后是什么生肖| 流鼻涕是什么原因| 牙龈肿痛吃什么| 姚明什么时候退役的| 菠萝是什么意思| 二氧化硅是什么| 蒂芙尼算什么档次| 狗狗窝咳吃什么药最好| 白带多是什么原因| 睡眠不好挂什么科门诊| 神经内科看什么病的| soso是什么意思| 排卵期是在什么时候| 辣眼睛是什么意思| 百度
 

百度 咱们的武磊,咱们的郜林,咱们的韦世豪,在联赛如此强势,但到了这样的舞台,却显得如此无力。

The 5 hardest things Josh Berry, a 15 year analytics professional, experienced while switching from Python to SQL. Offering examples, SQL code, and a resource to customize the SQL to your own project.



The 5 Hardest Things to do in SQL
Image by Editor

 

Many of us have experienced the core power of speed and efficiency delivered by centralizing compute within the Cloud Data Warehouse. While this is true, many of us have also realized that, like with anything, this value comes with its own set of downsides.?

One of the primary drawbacks of this approach is that you must learn and execute queries in different languages, specifically SQL. While writing SQL is faster and less expensive than standing up a secondary infrastructure to run python (on your laptop or in-office servers), it comes with many different complexities depending on what information the data analyst wants to extract from the cloud warehouse. The switch over to cloud data warehouses increases the utility of complex SQL versus python. Having been through this experience myself, I decided to record the specific transformations that are the most painful to learn and perform in SQL and provide the actual SQL needed to alleviate some of this pain for my readers.?

To aid in your workflow, you’ll notice that I provide examples of the data structure before and after the transform is executed, so you can follow along and validate your work. I have also provided the actual SQL needed to perform each of the 5 hardest transformations. You’ll need new SQL to perform the transformation across multiple projects as your data changes. We’ve provided links to dynamic SQL for each transformation so you can continue to capture the SQL needed for your analysis on an as needed basis!?

 

Date Spines

 

It is not clear where the term date spine originated, but even those who don’t know the term are probably familiar with what it is.

Imagine you are analyzing your daily sales data, and it looks like this:

sales_date product sales
2025-08-06 A 46
2025-08-06 B 409
2025-08-06 A 17
2025-08-06 B 480
2025-08-06 A 65
2025-08-06 A 45
2025-08-06 B 411

 

No sales happened on the 16th and 17th, so the rows are completely missing. If we were trying to calculate average daily sales, or build a time series forecast model, this format would be a major problem. What we need to do is insert rows for the missing days.

Here is the basic concept:

  1. Generate or select unique dates
  2. Generate or select unique products
  3. Cross Join (cartesian product) all combinations of 1&2
  4. Outer Join #3 to your original data

Customizable SQL for Datespine

The end result will look like this:

sales_date product sales
2025-08-06 A 46
2025-08-06 B 409
2025-08-06 A 17
2025-08-06 B 480
2025-08-06 A 0
2025-08-06 B 0
2025-08-06 A 0
2025-08-06 B 0
2025-08-06 A 65
2025-08-06 B 0
2025-08-06 A 45
2025-08-06 B 411

 

Pivot / Unpivot

 

Sometimes, when doing an analysis, you want to restructure the table. For instance, we might have a list of students, subjects, and grades, but we want to break out subjects into each column. We all know and love Excel because of its pivot tables. But have you ever tried to do it in SQL? Not only does every database have annoying differences in how PIVOT is supported, but the syntax is unintuitive and easily forgettable.?

Before:

Student Subject Grade
Jared Mathematics 61
Jared Geography 94
Jared Phys Ed 98
Patrick Mathematics 99
Patrick Geography 93
Patrick Phys Ed 4

 

Customizable SQL for Pivot

Result:

Student Mathematics Geography Phys Ed
Jared 61 94 98
Patrick 99 93 4

 

One-hot Encoding

 

This one isn’t necessarily difficult but is time-consuming. Most data scientists don’t consider doing one-hot-encoding in SQL. Although the syntax is simple, they would rather transfer the data out of the data warehouse than the tedious task of writing a 26-line CASE statement. We don’t blame them!?

However, we recommend taking advantage of your data warehouse and its processing power. Here is an example using STATE as a column to one-hot-encode.

Before:

Babyname State Qty
Alice AL 156
Alice AK 146
Alice PA 654
Zelda NY 417
Zelda AL 261
Zelda CO 321

 

Customizable SQL for One-Hot Encode

Result:

Babyname State State_AL State_AK State_CO Qty
Alice AL 1 0 0 156
Alice AK 0 1 0 146
Alice PA 0 0 0 654
Zelda NY 0 0 0 417
Zelda AL 1 0 0 261
Zelda CO 0 0 1 321

 

Market Basket Analysis

 

When doing a market basket analysis or mining for association rules, the first step is often formatting the data to aggregate each transaction into a single record. This can be challenging for your laptop, but your data warehouse is designed to crunch this data efficiently.

Typical transaction data:

SALESORDERNUMBER CUSTOMERKEY ENGLISHPRODUCTNAME LISTPRICE WEIGHT ORDERDATE
SO51247 11249 Mountain-200 Black 2294.99 23.77 1/1/2013
SO51247 11249 Water Bottle - 30 oz. 4.99 1/1/2013
SO51247 11249 Mountain Bottle Cage 9.99 1/1/2013
SO51246 25625 Sport-100 Helmet 34.99 12/31/2012
SO51246 25625 Water Bottle - 30 oz. 4.99 12/31/2012
SO51246 25625 Road Bottle Cage 8.99 12/31/2012
SO51246 25625 Touring-1000 Blue 2384.07 25.42 12/31/2012

 

Customizable SQL for Market Basket

Result:

NUMTRANSACTIONS ENGLISHPRODUCTNAME_LISTAGG
207 Mountain Bottle Cage, Water Bottle - 30 oz.
200 Mountain Tire Tube, Patch Kit/8 Patches
142 LL Road Tire, Patch Kit/8 Patches
137 Patch Kit/8 Patches, Road Tire Tube
135 Patch Kit/8 Patches, Touring Tire Tube
132 HL Mountain Tire, Mountain Tire Tube, Patch Kit/8 Patches

 

Time-Series Aggregations

 

Time series aggregations are not only used by data scientists but they’re used for analytics as well. What makes them difficult is that window functions require the data to be formatted correctly.

For example, if you want to calculate the average sales amount in the past 14 days, window functions require you to have all sales data broken up into one row per day. Unfortunately, anyone who has worked with sales data before knows that it is usually stored at the transaction level. This is where time-series aggregation comes in handy. You can create aggregated, historical metrics without reformatting the entire dataset. It also comes in handy if we want to add multiple metrics at one time:

  • Average sales in the past 14 days
  • Biggest purchase in last 6 months
  • Count Distinct product types in last 90 days

If you wanted to use window functions, each metric would need to be built independently with several steps.

A better way to handle this, is to use common table expressions (CTEs) to define each of the historical windows, pre-aggregated.

For example:

Transaction ID Customer ID Product Type Purchase Amt Transaction Date
65432 101 Grocery 101.14 2025-08-06
65493 101 Grocery 98.45 2025-08-06
65494 101 Automotive 239.98 2025-08-06
66789 101 Grocery 86.55 2025-08-06
66981 101 Pharmacy 14 2025-08-06
67145 101 Grocery 93.12 2025-08-06

 

Customizable SQL for Time Series Aggregate SQL

Result:

Transaction ID Customer ID Product Type Purchase Amt Transaction Date Avg Sales Past 14 Days Max Purchase Past 6 months Count Distinct Product Type last 90 days
65432 101 Grocery 101.14 2025-08-06 101.14 101.14 1
65493 101 Grocery 98.45 2025-08-06 98.45 101.14 2
65494 101 Automotive 239.98 2025-08-06 169.21 239.98 2
66789 101 Grocery 86.55 2025-08-06 86.55 239.98 2
66981 101 Pharmacy 14 2025-08-06 14 239.98 3
67145 101 Grocery 93.12 2025-08-06 53.56 239.98 3

 

Conclusion

 

I hope this piece helps shed some light on the different troubles that a data practitioner will encounter when operating within the modern data stack. SQL is a double-edged sword when it comes to querying the cloud warehouse. While centralizing the compute in the cloud data warehouse increases speed, it sometimes requires some extra SQL skills. I hope that this piece has helped answer questions and provides the syntax and background needed to tackle these problems.?

 
 
Josh Berry (@Twitter) leads Customer Facing Data Science at Rasgo and has been in the data and analytics profession since 2008. Josh spent 10 years at Comcast where he built the data science team and was a key owner of the internally developed Comcast feature store - one of the first feature stores to hit the market. Following Comcast, Josh was a critical leader in building out Customer Facing Data Science at DataRobot. In his spare time Josh performs complex analysis on interesting topics such as baseball, F1 racing, housing market predictions, and more.
 



小鱼吃什么 energy是什么牌子 肝有问题会出现什么症状 焦俊艳和焦恩俊是什么关系 什么样的嘴巴
脑供血不足吃什么药效果最好 带节奏是什么意思 msi是什么比赛 日出扶桑是什么意思 纳呆是什么意思
胃造影和胃镜有什么区别 古代医院叫什么 树叶像什么比喻句 金舆是什么意思 为什么没人穿卡帕
房早有什么危害 宣是什么意思 急救物品五定是什么 洋葱什么时候种植 如履薄冰什么意思
3人死亡属于什么事故tiangongnft.com 消防支队长是什么级别hcv9jop3ns0r.cn 虾青素有什么作用hcv9jop0ns1r.cn 焦虑症是什么意思hcv8jop1ns1r.cn 动物的脖子有什么作用hcv9jop4ns8r.cn
胃病吃什么食物养胃hcv8jop9ns6r.cn kids是什么品牌hcv7jop9ns4r.cn 紧急避孕药有什么危害hcv8jop8ns8r.cn 文科女生学什么专业好hcv8jop3ns2r.cn 侯亮平是什么级别hcv8jop5ns2r.cn
口加女念什么hcv7jop6ns5r.cn 大自然的馈赠什么意思jinxinzhichuang.com 01年属蛇的是什么命hcv8jop5ns1r.cn 混合痔是什么意思hcv7jop7ns4r.cn 串串房是什么意思hcv8jop8ns6r.cn
巴黎世家是什么hcv8jop4ns1r.cn 荨麻疹吃什么药最有效hcv9jop4ns5r.cn 11月10日是什么星座hcv8jop8ns3r.cn 角膜炎是什么症状hcv8jop5ns6r.cn lst是什么意思hcv9jop3ns6r.cn
百度