Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Wednesday, May 26, 2010

SQL window functions

Maybe these are easier to understand if you consider the degenerate case where no partition is specified - then the whole table is one partition:

select seqnum, count(*) over () from doctor

gives you count(*) repeated on each row, a bit like Sybase used to do if you missed out the group by.

select seqnum, row_number() over (order by seqnum) from doctor

gives you the sort order number for each row when sorted by seqnum

Similarly, window aggregation functions work without an order by:

select seqnum, count(*) over (partition by doctor_seqnum) from episode

gives (repeated for each episode for a particular Doctor) the number of episodes featuring that Doctor. (You couldn't do row_number() here because it requires a sort).

Followers

Blog Archive