Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
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
Labels (1)
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;