Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to get cross time data by SQL

NameStarttimeEndtime
A1/1/2013 10:001/1/2013 12:00
A                              1/1/2013 14:001/1/2013 17:00
A1/1/2013 13:001/1/2013 16:00
B1/1/2013 13:001/1/2013 18:00

in the raw data i have some data is crossed in time on the same person (A)

i want to ask how to convert crossed time into one by SQL?

NameStarttimeEndtime
A1/1/2013 10:001/1/2013 12:00
A                            1/1/2013 13:001/1/2013 17:00
B1/1/2013 13:001/1/2013 18:00
1 Reply
hic
Former Employee
Former Employee

RawData:

Load Name,

  TimeStamp#(Starttime,'M/D/YYYY hh:mm') as Starttime,

  TimeStamp#(Endtime,'M/D/YYYY hh:mm') as Endtime

inline

[Name,Starttime,Endtime

A,1/1/2013 10:00,1/1/2013 12:00

A,1/1/2013 14:00,1/1/2013 17:00

A,1/1/2013 13:00,1/1/2013 16:00

B,1/1/2013 13:00,1/1/2013 18:00];

Data:

Load *,

  If(Name=Peek(Name) and Starttime < Peek(Endtime),Peek(TimeSlotID),

  Autonumber(Name & Starttime)) as TimeSlotID

  Resident RawData Order By Name, Starttime;

AggregatedData:

NoConcatenate Load

  Name,

  Timestamp(Min(Starttime),'M/D/YYYY hh:mm') as Starttime,

  Timestamp(Max(Endtime),'M/D/YYYY hh:mm') as Endtime

  Resident Data

  Group By Name,TimeSlotID;

Drop Table Data, RawData;