0

I have a table like

ColumnA ColumnB ColumnC
ABC TextA 3
EFG TextB 1
EFG TextC 2

How do I write a SELECT statement that will return the # of rows for ColumnA and ColumnB based on the values of ColumnC

Expect results:

ColumnA ColumnB
ABC TextA
ABC TextA
ABC TextA
EFG TextB
EFG TextC
EFG TextC
3
  • what does select version(); show? and is there some expected maximum value of column c? Commented Oct 13, 2021 at 2:25
  • Maximum value of ColumnC is less than 100, total volume is not huge so performance is not critical Commented Oct 13, 2021 at 2:25
  • Version is 8.0.19-commercial Commented Oct 13, 2021 at 2:26

1 Answer 1

1

You can use a recursive cte:

with recursive cte(a, b, c) as (
    select cola, colb, colc - 1 from t
    union all
    select a, b, c - 1 from cte where c > 0
)
select a, b from cte order by a;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.