Advertisement
ivansky

Untitled

Jun 2nd, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. SELECT
  2. a.item_id,
  3. a.price,
  4. a.mod_id,
  5. a.compl_id,
  6. i.*
  7. FROM (
  8. (SELECT * FROM some_table p WHERE p.price >= 400000 GROUP BY p.item_id ORDER BY p.price ASC LIMIT 5)
  9. UNION ALL
  10. (SELECT * FROM some_table p WHERE p.price < 400000 GROUP BY p.item_id ORDER BY p.price DESC LIMIT 5)
  11. ) a
  12. LEFT JOIN module_catalog_item i ON i.id = a.item_id
  13. ORDER BY ABS(a.price - 400000) ASC
  14. LIMIT 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement