确定患者将来是否有另一条记录

时间:2017-09-18 15:58:07

标签: sql sql-server

我有一张代表约会的表格:

<ViewCell>
  <ViewCell.View>
    <StackLayout BackgroundColor="Red">
      <Label Text="wtf" TextColor="Black"/>
      <label Text="{Binding Test}" TextColor="Black"/>
    </StackLayout>
  </ViewCell.View>
</ViewCell>

所以我有一个查询,让我所有预约的患者,但实际上没有出现:

Appointments
- id
- doctor_id
- patient_id
- start_date
- attended (bool)

但我要补充的是,如果患者没有参加,但将来会再次预约:

select 
        patient_id
from appointments a
where attended=false

3 个答案:

答案 0 :(得分:1)

select 
    a.patient_id
    , cast(case when a_future.patient_id is not null then 1 else 0 end as bit) has_future_appointment
from
    appointments a
    outer apply
        (
            select top 1 a_future.patient_id
            from appointments a_future
            where
                a_future.patient_id = a.patient_id
                and a_future.[start_date] > GETDATE()
        ) a_future
where attended=0

答案 1 :(得分:0)

一种过滤方式

ngFor

答案 2 :(得分:0)

您可以在此检查患者日期大于当前

select patient_id
from appointments a
where attended = falase and start_date < systdate();