Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

How to order and partition by various columns?

Asked by Christian Parsons Aug 3, 2023 868 views 1 answer
Share

About this question

I am deploying PostgreSQL. There is a table having 2 columns int he figure below:

I need to include a new column having a distinct id respective to partitions by name and category. Then, I need a random sample selecting 2 distinct ids since under every id, there will be a huge amount of historical data.  I want to know how to correct my mistakes.

SELECT
  dense_rank() over (partition by name, category order by category) as unique_id,
  *
FROM
 example_table
After this, presumably I'll have to use RAND() somewhere but how do I do this?


Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.