DecebalICT

Select quotes with preference for ‘old’ ones

Mar 5th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.24 KB | None | 0 0
  1. SELECT   quote
  2. FROM (
  3.     SELECT quote
  4.     ,      DATEDIFF('DAY', last_selected, CURDATE()) * RAND() AS randWeighted
  5.     FROM   quotesTest
  6.     WHERE  DATEDIFF('DAY', last_selected, CURDATE()) > 7
  7. )
  8. ORDER BY randWeighted DESC
  9. LIMIT    1
  10. ;
Advertisement
Add Comment
Please, Sign In to add comment