sql >> Database >  >> RDS >> Mysql

MYSQL SELECT rang van gebruiker (meer dan x &minder dan y)

Je kunt het zo doen

SELECT
  tu.id,
  tr.name,
  tu.points
FROM table_ranks as tr
  LEFT JOIN (SELECT * FROM table_ranks LIMIT 1,69596585953484) as l
    ON l.points_needed = (SELECT MIN(points_needed) FROM table_ranks WHERE points_needed > tr.points_needed limit 1)
  LEFT OUTER JOIN table_users AS tu ON tu.points >= tr.points_needed AND tu.points < l.points_needed
WHERE tu.id IS NOT NULL
group by tu.id

Fiddle

Uitgang

-------------------------
| id  | points   | name |
-------------------------
| 1   |   lvl0   | 2    |
| 2   |   lvl1   | 10   |
| 3   |   lvl2   | 21   |
| 4   |   lvl2   | 29   |
-------------------------


  1. mysql_upgrade mislukt - innodb-tabellen bestaan ​​niet?

  2. Sequelize.js externe sleutel

  3. SQL Server String-functies (volledige lijst)

  4. DUBBEL versus DECIMAAL in MySQL