Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. create table appointments
  2. (
  3. id serial not null constraint appointments_pkey primary key,
  4. patient_id varchar(255) not null,
  5. date timestamp(0) not null
  6. );
  7.  
  8. SELECT
  9. (
  10. SELECT MIN(ap.date) FROM appointments ap
  11. WHERE ap.date >= NOW() AND ap.patient_id = '1'
  12. ) AS next,
  13. (
  14. SELECT MAX(ap.date) FROM appointments ap
  15. WHERE ap.date < NOW() AND ap.patient_id = '1'
  16. ) AS last
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement