Is there a where condition to compare the value of the string after splitting?

YuTing

Database:SAP HANA

First table is original data.

Original

MATNR EAU QTY
1 30 1
1 30 50
2 70 1
2 70 50
2 70 100
3 10 1

Second table is output after group by.

Output ( Group by MATNR )

MATNR EAU QTY
1 30 1, 50
2 70 1, 50, 100
3 10 1

Third table is the expected result.

Output ( Where EAU > second QTY )

MATNR EAU QTY
2 70 1, 50, 100

Is there a sql like WHERE SPLIT(QTY, ', ')[1] > EAU ?

Gordon Linoff

You don't specify what database you are using, but one method would use row_number():

select matnr, eau,
       listagg(qty, ', ') within group (order by qty)
from (select t.*,
             row_number() over (partition by matnr order by qty) as seqnum
      from t
     ) t
group by matnr, eau
having eau > sum(case when seqnum = 2 then qty end) ;

Note: This uses generic SQL. The exact syntax (particularly for the string aggregation) depends on the database you are using.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

why am I not able to compare a space in string after splitting to a space?

if else condition in angularjs to compare string and int value

Query condition where a value is in a comma separated string

ArrayIndexOutOfBoundsException after splitting a string

Getting "System.String[]" instead of actual value after splitting.

Splitting string by new line with a condition

Compare two list and get first value after condition is satisfied

Splitting a string in to multiple value

Splitting a string into one value

Compare with int and string in IF condition

Get value of substrings after splitting

Splitting a string after certain characters?

Generalizing the conditions after splitting of a string

Splitting a string to compare each word to an arraylist

Get first value after Where-Object condition

Comparing string value and splitting them

Splitting String Value Using Regex

Splitting string in key value with regex

Splitting string value c#

TypeORM, add condition in `where` if value is presented and not empty string

Mongo Aggregation Query - Filter Condition where string contains value

how to use WHERE condition to find specific value from string in table?

Trying to compare old v new value after the string update

Adding a char after a certain value and condition of string Java

Problem with splitting string into tokens with strtok - Char arrays are empty after splitting

Get [ ] interface{} after splitting a string by comma in go

Splitting string before and after certain parameters in Go

Returning array in Javascript function after splitting string

Splitting a string to remove everything after a delimiter