Guest User

Untitled

a guest
May 20th, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. id | employment_date | name
  2. -------------------------------
  3. 23 | 1980-01-11 | peter
  4. 21 | 1980-09-02 | sandra
  5. 34 | 1982-04-12 | steven
  6. 4 | 1982-06-14 | claudia
  7. 45 | 1983-10-12 | chuck
  8. 56 | 1984-03-16 | bob
  9. 1 | 1987-03-23 | kevin
  10.  
  11. (
  12. SELECT id,@basedate:=employment_date AS employment_date,name
  13. FROM employees WHERE name='claudia'
  14. )
  15. UNION
  16. (
  17. SELECT * FROM employees
  18. ORDER BY if (employment_date>@basedate,employment_date,'9999-12-31') ASC
  19. LIMIT 2
  20. )
  21. UNION
  22. (
  23. SELECT * FROM employees
  24. ORDER BY if (employment_date<@basedate,employment_date,'0001-01-01') DESC
  25. LIMIT 2
  26. )
  27. ORDER BY employment_date ASC
Advertisement
Add Comment
Please, Sign In to add comment