繁体   English   中英

使用条件AND NOT EXISTS将SQL转换为HQL

[英]Transform SQL to HQL with criteria AND NOT EXISTS

我需要转换此SQL语句HQL,但我认为NOT EXISTS在HQL中不起作用,请帮助我!

SELECT doctor.idUser, schedule.idSchedule, schedule.timeStart, schedule.day
FROM doctor, schedule
    WHERE schedule.day='LUNES'
        AND schedule.timeStart > '08:00:00'
        AND doctor.idUser= '1'
        AND doctor.idUser = schedule.idUserDoctor
AND NOT EXISTS( SELECT *    FROM appointment
    WHERE schedule.idSchedule = appointment.idSchedule
        AND doctor.idUser = schedule.idUserDoctor
        AND appointment.appointmentDate ='2012-09-06')
AND NOT EXISTS ( SELECT * FROM temporaryschedule
        WHERE schedule.idSchedule = temporaryschedule.idSchedule
        AND doctor.idUser = schedule.idUserDoctor"
        AND temporaryschedule.appointmentDate='201-09-06')
ORDER BY schedule.timeStart ASC

不幸的是,您没有提供有关您的域模型的任何信息,因此我们在这里需要做很多假设...首先,尽管您可能希望映射它,但我并没有考虑到医生与日程表之间的任何映射关联。 每一个好的设计,我使用参数而不是文字。 我假设所有引用的表都已映射,并且正在对类使用“逻辑名称映射”。 最后,我将您的列名用作域模型属性名...

select ...
from Doctor d, Schedule s
where s.day = :day
  and s.timeStart > :startTime
  and d.idUser = :doctorId
  and d.idUser = s.idUserDoctor
  and not exists (
      select *
      from Appointment appt
      where s.idSchedule = appt.idSchedule
        and d.idUser = s.idUserDoctor
        and apt.appointmentDate = :apptDate
  )
  and not exists (
      select *
      from TemporarySchedule ts
      where s.idSchedule = ts.idSchedule
        and d.idUser = s.idUserDoctor
        and ts.appointmentDate = tempSchedDate
  )
order by s.startTime asc

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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