So I asked this question a while back and now I've been confronted with a nasty variation.
Say I have this table:
ID Date Special
1 2001-01-11 1
1 2003-03-03
1 2002-02-22 1
2 2001-01-11 1
2 2002-02-22 1
I need to enumerate these records, both by the date, but also depending on if the record was marked as Special
or not.
The ideal output would be as such:
ID Date Special Num
1 2001-01-11 1 1
1 2003-03-03
1 2002-02-22 1 2
2 2001-01-11 1 1
2 2002-02-22 1 1
Here's the table:
CREATE TEMPORARY TABLE temp_table(id INT, dt DATE, Special INT);
INSERT INTO temp_table VALUES
(1, '2001-01-11', 1),
(1, '2003-03-03', NULL),
(1, '2002-02-22', 1),
(2, '2001-01-11', 1),
(2, '2002-02-22', 1);
I would love to be able to modify the answer I got to the aboveformentioned question, but it uses that declarative side of SQL that I'm terrible at. Thanks for looking at this!