Group data based on a specific value

I have a table named x, the table has an id column and a retry status column. The identifier can store the same values ​​even from 6 of them, while the repeat status increases each time you insert the identifier 1,2 ... n. If a new identifier is inserted, the retry status starts at 1, for example,

xid repeat_status xx123 1 xx123 1 xx123 2 xx123 3 xx123 3 xxx45 1 xxx45 2 xxx45 2 

How can I modify the query below to return something like this:

  xid repeat_status xx123 1 xx123 2 xx123 3 xxx45 1 xxx45 2 SELECT xid ,repeat_status FROM x GROUP BY repeat_status; 
+4
source share
2 answers

you can also try a group on request, for example

 SELECT xid, repeat_status FROM x GROUP BY xid,repeat_status 

Message: What is the difference between DISTINCT and GROUP BY?

DISTINCT and GROUP BY usually generate the same query plan, so performance should be the same for both query constructs.

but this is for sql server

+3
source
 select distinct xid, repeat_status from x order by xid, repeat_status 
+3
source

Source: https://habr.com/ru/post/1444180/


All Articles