Access SQL Subquery Criteria based on Next Record -


i have column of qualitychecktimes. have different table starttimes , endtimes of productionskids.

i need query returns each qualitychecktime, minimum skidid , maximum skidid based on starttimes , endtimes.

sample data

 qcchecktimes        12:00         1:00         2:00     skidid   skidstarttime  skidendtime         1        12:05     12:20         2        12:21     12:40         3        12:41     12:50         4        12:51      1:06 

expected output:

 qcchecktimes minskidid  maxskidid       12:00     skid1      skid3          1:00     skid4        ...         2:00       ...   

i've tried few things, crux of need find way matching skid times between 2 qualitycheck times, qualitytimes being on separate rows.

select... [skidstartdatetime] >= [qualitysamples_tbl].[sampledatetime] , [skidenddatetime] < next?? [qualitysamples_tbl].[sampledatetime]); 

you can use subquires , hour() function achieve this: try this:

table1 contains: qcchecktimes

table2 contains: skidid,skidstarttime,skidendtime

select table1.qcchecktimes,         iif([minofid] null, "...", "skid" & [minofid])  minskidid,         iif([c].[maxofid] = [b].[minofid], "...",         iif([maxofid] null, "...", "skid" & [maxofid])) maxskidid    (table1          left join (select table1.qcchecktimes,                            min(table2.skidid) minofid                       table1,                            table2                      (( ( hour([skidendtime]) ) = hour([qcchecktimes]) ))                     group  table1.qcchecktimes) b                 on table1.qcchecktimes = b.qcchecktimes)         left join (select table1.qcchecktimes,                           max(table2.skidid) maxofid                      table1,                           table2                     (( ( hour([skidendtime]) ) = hour([qcchecktimes]) ))                    group  table1.qcchecktimes) c                on table1.qcchecktimes = c.qcchecktimes  group  table1.qcchecktimes,            iif([minofid] null, "...", "skid" & [minofid]),            iif([c].[maxofid] = [b].[minofid], "...",            iif([maxofid] null, "...", "skid" & [maxofid]));  

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -