A
A
Andrey Strelkov2020-01-20 08:43:14
MySQL
Andrey Strelkov, 2020-01-20 08:43:14

How to add an enumerator to groups of similar records in a SQL query?

Good afternoon, there is a table describing the characteristics of devices of the same type, but with slight differences in properties, the table is as follows:
ID; DEVICE; FIELD; VALUE
1 ; Monitor; Model; LG
2 ; Monitor; Serial number; 123453
; Monitor; Date of issue; 01/01/2020
4 ; Monitor; Model; LG
5 ; Monitor; Serial number; 234566
; Monitor; Date of issue; 01/02/2020
7 ; Monitor; Model; LG
8 ; Monitor; Serial number; 345679
; Monitor; Date of issue; 01/03/2020
At the output, you need to get the following result:
ID; DEVICE; FIELD; VALUE; GROUP
1 ; Monitor; Model; LG; 1
2 ; Monitor; Serial number; 12345; one
3; Monitor; Date of issue; 01/01/2020; 14
; Monitor; Model; LG; 2
5 ; Monitor; Serial number; 23456; 26
; Monitor; Date of issue; 01/02/2020; 27
; Monitor; Model; LG; 38
; Monitor; Serial number; 34567; 39
; Monitor; Date of issue; 01/03/2020; 3
i.e. each monitor now has a certain identifier, which the number combines its attributes into a group
. You can get such an enumerator, for example, based on the name of the Model field (this field is always there, and always comes first), maybe somehow in the request you can respond to it and to make data based on it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
idShura, 2020-01-20
@idShura

You can www.sql-tutorial.ru/ru/book_rank_dense_rank_functi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question