Explode each row into multiple rows by splitting a column of a given computed range
try:
=INDEX(QUERY(SPLIT(FLATTEN(A1:A&"×"&SPLIT(B1:B, ", ", )&"×"&C1:C), "×"),
"where Col3 is not null"))
how to split single row to multiple rows in mysql
We can use a cross/inner join approach here with the help of SUBSTRING_INDEX()
:
SELECT
t1.datetime1,
t1.count,
t1.num1,
t2.num2
FROM
(
SELECT datetime1, count, SUBSTRING_INDEX(num1, ',', 1) AS num1
FROM yourTable
UNION ALL
SELECT datetime1, count, SUBSTRING_INDEX(num1, ',', -1)
FROM yourTable
) t1
INNER JOIN
(
SELECT datetime1, count, SUBSTRING_INDEX(num2, ',', 1) AS num2
FROM yourTable
UNION ALL
SELECT datetime1, count, SUBSTRING_INDEX(num2, ',', -1)
FROM yourTable
) t2
ON t2.datetime1 = t1.datetime1
ORDER BY
t1.datetime1,
t1.num1,
t2.num2;
Demo
Split single row value to multiple rows in Snowflake
I was able to resolve this by using LATERAL FLATTERN like a joining table and selecting the value from it.
SELECT DISTINCT A.VALUE AS COL_NAME
FROM "DB"."SCHEMA"."TABLE",
LATERAL SPLIT_TO_TABLE(COL_NAME,';')A
How to split the data in a single row into multiple rows in SQL?
If data type of locationID is varchar then:
create table projects (ProjectID int, LocationID varchar(50));
insert into projects values(1, '[1,2,3,4]');
insert into projects values(2, '[2,3]');
Query:
select projectid, value
from projects
CROSS APPLY STRING_SPLIT(replace(replace(locationid,'[',''),']',''),',')
Output:
projectid | value |
---|---|
1 | 1 |
1 | 2 |
1 | 3 |
1 | 4 |
2 | 2 |
2 | 3 |
Related Topics
Is There a Logical Way to Think About List Indexing
How to Coerce a List Object to Type 'Double'
Predict.Lm() in a Loop. Warning: Prediction from a Rank-Deficient Fit May Be Misleading
Dplyr - Using Mutate() Like Rowmeans()
How to Convert Integer into Categorical Data in R
Converting a \U Escaped Unicode String to Ascii
Read and Rbind Multiple CSV Files
Count How Many Values in Some Cells of a Row Are Not Na (In R)
Cleaning 'Inf' Values from an R Dataframe
Apply a Function to a Subset of Data.Table Columns, by Column-Indices Instead of Name
Add Percentage Labels to a Stacked Barplot
Knitr Gets Tricked by Data.Table ':=' Assignment
How to Delete Rows from a Data.Frame, Based on an External List, Using R
Too Few Periods for Decompose()