如何创建一个列表,显示一周内所有有服务的唯一工人

5lhxktic  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(127)

我试图创建一个查询,显示在一周内至少轮班的工人的列表,但在我创建的查询中,工人的姓名根据他们在这一期间完成的轮班次数多次出现。

WITH time_frame AS
  (SELECT date_trunc('week',NOW())-interval '1 week')

select 
    null as "Employer Ref",   
    ff.id as "Personnel Ref", 
    null as "Employment Sequence No",
    ff.first_name as Forename, 
    ff.last_name as Surname,  
    null as "Second forename",
    null as "Third forename ",

    case ff.gender
    when 'F' then 'Miss' 
    when 'M' then 'Mr' 
    else null 
    end as Title,

    null as "Known as",            

    ff.address1 as "Address line 1",
    ff.address2 as "Address line 2",
    ff.city as "Address line 3",
    null as "Address line 4",
    null as "Address line 5",

    lp.postcode as Postcode,
    'UK' as Country,
    null as "Telephone number",    

    ff.gender as gender,
    ff.birth_date as "Date of birth",
    ff.mobile as "Mobile Telephone",
    au.email as "Email Address",
    ff.sort_code as "Bank1 sort code",
    ff.account_number as "Bank1 account number",
    concat(ff.first_name,' ',ff.last_name) as "Bank1 account name" 

from booking_booking bb 

join freelancer_freelancer ff on  bb.freelancer_id = ff.id
join job_jobrequest jj on bb.jobrequest_id = jj.id
join auth_user au on au.id = ff.user_id
join location_postcode lp on lp.id = jj.postcode_id

WHERE bb.status != 'FC'
     AND bb.status != 'BC'
     AND bb.status != 'BU'
     AND jj.agency_id IN('1')
     AND date_trunc('week',jj.date) =
       (SELECT *
        FROM time_frame)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题