sql server - SQL identifying the first occurance in a list -


using sql server i'm trying label first occurrence in query result, results this...

enter image description here

i can identify first of each this:

enter image description here

can done case statement or similar? appreciated!

thanks

use of row_number() should enable this

select    breakfast  , case when rn = 1 1 else 0 end first_occur (        select           breakfast        , row_number() on (partition breakfast order id desc) rn        your_table      ) x 

but isn't known order (i've assumed id desc), there might datetime or else in table use that.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -