I want to write a query to group my two columns based on third column and show result in a row as shown below in SQLite CAn anybody guide me how can I write query for such structure Table Structure
CREATE TABLE `Table1` (
`Variable_col` TEXT,
`TimeComes_Col` datetime,
`TimeGoes_Col` datetime)
Dummy Data
Insert Into Table1 Values('var1','2017-03-16 10:00:00',''),('var1','','2017-03-16 10:05:00'),('var1','2017-03-16 10:10:00',''),('var2','2017-03-16 10:15:00','')
Tried So far but not getting result as wanted
WITH RECURSIVE cte1 as(select Variable_Col,TimeComes_Col, (SELECT COUNT()+1 FROM ( SELECT DISTINCT TimeComes_Col FROM Table1 AS t WHERE TimeComes_Col < Table1.TimeComes_Col )) as rn from Table1 where TimeComes_Col <> ''),
cte2 as(select TimeGoes_Col, (SELECT COUNT()+1 FROM (SELECT DISTINCT TimeGoes_Col FROM Table1 AS t WHERE TimeGoes_Col < Table1.TimeGoes_Col ) )as rn from Table1 where TimeGoes_Col <> '')select Variable_Col, TimeComes_Col, TimeGoes_Col from cte1 a left join cte2 b on a.rn = b.rn
See Question&Answers more detail:os