简体   繁体   中英

Extract workspace that there is no data entry more than one month

I have a table Timesheet with these columns:

IDWORKSPACE | DTDATE | workeddays

And another table TWorkspace :

IDWORKSPACE | TYPE | NAME

How could I extract all workspace names that there is no entry data for worked days for more than one month?

the below code prints records in TWORKSPACE table if there is no record in TIMESHEET table matching with IDWORKSPACE

select * from tworkspace w
where not exists (
   select 1 from TIMESHEET t
   where w.IDWORKSPACE = t.IDWORKSPACE
   group by IDWORKSPACE
   having sum(workeddays) > 30
)

Please, check if this works:

select *
from TWorkspace
where IDWORKSPACE in(
    select IDWORDSPACE
    from Timesheet
    where DTDATE >= dateadd(mm, getdate(), -1)
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM