Hacker News new | ask | show | jobs
by withinboredom 976 days ago
You aren't wrong.

http://sqlfiddle.com/#!15/7eb3a/7

Here's a pretty simple/normalish way to handle the edge cases. This one (without distinct) is far more consistent (wall-clock-wise, doesn't depend on caches): http://sqlfiddle.com/#!15/7eb3a/9

Note that order 2 is after order 4 in the example schema.

1 comments

If you just need customer id and order id (and nothing from the original orders table), you can simplify it further http://sqlfiddle.com/#!15/7eb3a/10