sql - Return results where first entry is 1 and all subsequent rows are 0 -


i m working on weird sql query

 patient_id    count    order_no  1               1          1  2               1          2    2               0          3  2               0          4  3               1          5  3               0          6 

where need count patient above, every new patient , count column 1. if repeated , below entry should 0

i m confused how should make work in sql

in order make first entry 1 , subsuqent entries 0, believe need ranking partition order number. please checkout sqlfiddle below test results.

http://www.sqlfiddle.com/#!3/4e2e2/17/0

select patient_id ,case when r.rank = 1   1  else 0  end , order_number (   select    order_number   ,patient_id   ,row_number() on (partition patient_id order order_number)[rank]       patienttable )r 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -