Optimize Your SQL Code with This Window Function

Replace your painful CTEs by using FIRST_VALUE()

Madison Schott
Towards Data Science
3 min readFeb 16, 2022

--

Photo by Say Cheeze Studios on Unsplash

We’ve all come across this block of SQL code… It’s easy to read, but something about it is just, well, annoying. Often code that could be written with one query is seen written as a CTE.

While cleaning up some old data models, I’ve come across code like this a lot. Other code…

--

--

Analytics Engineer @ ConvertKit, author of the Learn Analytics Engineering newsletter and The ABCS of Analytics Engineering ebook, health & wellness enthusiast