A 0 2 A 2 4 A 4 6 A 6 8 A 8 10 A 10 12 A 12 14 A 14 16 A 16 18 A 18 20 WITH DATA_RANGE AS ( SELECT NAME,DATA_VALUE,LEAD(DATA_VALUE) OVER ( PARTITION BY 名称 ORDER BY DATA_VALUE)NEXT_VALUE FROM ( SELECT NAME,MIN_VAL V1,MIN_VAL + PARTITION V2,MIN_VAL + PARTITION * 2 V3,MIN_VAL + PARTITION * 3 V4,MIN_VAL + PARTITION * 4 V5,MIN_VAL + PARTITION * 5 V6 ,MIN_VAL + PARTITION * 6 V7,MIN_VAL + PARTITION * 7 V8,MIN_VAL + PARTITION * 8 V9,MIN_VAL + PARTITION * 9 V10,MAX_VAL V11 FROM ( SELECT NAME,MIN_VAL,MAX_VAL,(MAX_VAL-MIN_VAL)/ 10 PARTITION FROM ( SELECT 名称,MAX(VALUE)MAX_VAL,MIN(VALUE)MIN_VAL FROM TAB GROUP BY NAME)A)A)A UNPIVOT (DATA_VALUE FOR DATA_TYPE IN (V1,V2,V3,V4,V5,V6,V7,V8, V9,V10,V11)) ORDER BY NAME,DATA_VALUE) SELECT NAME,DATA_VALUE,NEXT_VALUE FROM DATA_RANGE WHERE NEXT_VALUE IS NOT NULL ORDER BY NAME ,DATA_VALUE I am having hard time thinking for a posible solution for this problem: i have one table that has value asname valueA 0A 10A 20B 0B 50B 70B 100Requirement: i) find min and max value for each name i.e.name min maxA 0 20B 0 100then divide the min and max to 10 equal parts and display like:name range1 range2A 0 2A 2 4A 4 6A 6 8A 8 10A 10 12A 12 14A 14 16A 16 18A 18 20and similarly for B.I tried something like this:SELECTname,MIN,MAX,(MAX - MIN)/10 PARTITION_VALUE,FROM(SELECTname,MIN(value) MIN,MAX(value) MAXFROM [table]GROUP BY name) Acalculated min value, max value and the partition_value that will help in defining the range.. i.e. dividing min and max value in 10 different parts.I am just unable to proceed further.Thanks 解决方案 HI here is the sql query from which you can get max & min values of namesselect name, (select MIN(value) from table1 b where b.name=a.name) as mini,(select MAx(value) from table1 c where c.name=a.name) as maxi from table1 a group by namethanks.hi Deepak,Thank you for the answer, but my desired output is something else.I need to first find min and max values as per name (which is the output from your query).After that based on those value, I need to create 10 rows with equal partitions for each name.its like A has min as 0 and max as 20.so its partition would look likeA 0A 2A 4A 6A 8A 10A 12A 14A 16A 18A 20After doing this, i require the output as:A 0 2A 2 4A 4 6A 6 8A 8 10A 10 12A 12 14A 14 16A 16 18A 18 20WITH DATA_RANGE AS(SELECT NAME, DATA_VALUE, LEAD(DATA_VALUE) OVER (PARTITION BY NAME ORDER BY DATA_VALUE) NEXT_VALUE FROM(SELECT NAME,MIN_VAL V1,MIN_VAL+PARTITION V2,MIN_VAL+PARTITION*2 V3,MIN_VAL+PARTITION*3 V4,MIN_VAL+PARTITION*4 V5,MIN_VAL+PARTITION*5 V6,MIN_VAL+PARTITION*6 V7,MIN_VAL+PARTITION*7 V8,MIN_VAL+PARTITION*8 V9,MIN_VAL+PARTITION*9 V10,MAX_VAL V11FROM(SELECT NAME,MIN_VAL,MAX_VAL,(MAX_VAL-MIN_VAL)/10 PARTITIONFROM(SELECT NAME,MAX(VALUE) MAX_VAL, MIN(VALUE) MIN_VAL FROM TABGROUP BY NAME) A) A) AUNPIVOT(DATA_VALUEFOR DATA_TYPE IN (V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11))ORDER BY NAME, DATA_VALUE)SELECT NAME, DATA_VALUE, NEXT_VALUE FROM DATA_RANGEWHERE NEXT_VALUE IS NOT NULLORDER BY NAME,DATA_VALUE 这篇关于需要有关sql查询的帮助。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 15:48