C
C
cicatrix2017-11-25 19:07:15
SQL
cicatrix, 2017-11-25 19:07:15

How to calculate the minimums and maximums in the table by the criterion?

We have the following data set:

sernum		range_id
5011120001	2
5011120015	3
5011120016	3
5011120019	4
5011120020	4
5011120021	4
5011120022	4
5011120031	5
5011120032	5
5011120034	6
5011120035	6
5011120037	7
5011120038	7
5011120039	7


It is necessary to build a table where for each range_id the minimum and maximum values ​​would be indicated:
range_id	min		max
2		5011120001	5011120001	
3		5011120015	5011120016	
4		5011120019	5011120022	
5		5011120031	5011120032	
6		5011120034	5011120035	
7		5011120037	5011120039

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2017-11-25
@cicatrix

SELECT range_id, MIN(sernum), MAX(sernum)
FROM table_name
GROUP BY range_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question