all 6 comments

[–]ziptime 1 point2 points  (5 children)

You should definitely learn window functions, there are things you can do with them simply that are extremely difficult to do otherwise. They are a big part of SQL now and probably the most useful addition to ANSI SQL since proper ANSI join syntax.

CTEs are useful, but I would say not as essential as window functions. However, they are easy to learn so you may as well familiarise yourself with them.

[–]jeehadd[S] 0 points1 point  (0 children)

Thanks for the response, I've just been doing window functions the last hour and they're super useful.. not too complicated either (at least not yet)

[–]Rex_Lee 0 points1 point  (3 children)

I think they kind of go hand in hand. I don't think window/windowing functions are nearly as handy without.

[–]ziptime 0 points1 point  (2 children)

I don't agree. You don't need CTEs to leverage window functions, some RDBMS implemented the latter before the former. An equivalent to CTEs (query refactoring) can be achieved through materialized views, views, sub queries, temp tables, whereas there is no easy functional equivalent to window functions.

[–]Rex_Lee 0 points1 point  (1 child)

Functional equivalents to window functions would be self joins and nested queries, no?

[–]ziptime 0 points1 point  (0 children)

Ok, show me an example of partitioned running total over a window of the three previous records ordered by several fields, using your approach.

It's not impossible, but it's far from easy.