Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get the rank field with more than one source in sql

could you, please, help me with SQL-query: I need to add the additional column with rank_2 which will show whether the source has more than 1 source_ids.

So, I need to get this result:
enter image description here

I don’t know how to write a query to get rank_2, which will contain 1 when the source has the only source_id (like the source "b") and contain 2 when the source has 2 or more source_ids (like the source "a").

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming window functions are available you can use a query like so:

select *
     , case when count(*) over (partition by date, source_name) = 1 then 1 else 2 end as rank_2
from t
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading