0

I was trying to do like a command with disord.js and the MAX() function that sorts the highest number of timescountedweek column, and also that row's ID and username.

This is what I have:

let sql = `SELECT
              username,
              userid,
              timescountedweek
          FROM
              userstats
          WHERE
           timescountedweek = (SELECT max(timescountedweek) FROM userstats);`

           db.get(sql, (err, row) => {
            if (err) {
              return console.error(err.message);
            }

              console.log(row.username)
              console.log(row.timescountedweek)
              console.log(row.userid)

          })

There is an issue here if I start this and it logs those 3 "rows" It logs the correct username and timescountedweek, but the userid is something totally different.

How it logs:

!2019#4392 41 235506020267327500

How it should log:

!2019#4392 41 336936521120874497

image of the database: https://i.stack.imgur.com/SLsfE.png

  • Just something that i found is that if a userid is for example 235506020267327488, it logs it as 235506020267327500 – this is co not cool Sep 12 '20 at 11:26
  • 1
    Does it help if you convert the user IDs to strings (e.g. see https://stackoverflow.com/questions/12419693/convert-integer-to-text-in-sqlites-select-query )? It looks like those IDs are being converted to JS numbers which are too large to be stored exactly (see https://stackoverflow.com/questions/307179/what-is-javascripts-highest-integer-value-that-a-number-can-go-to-without-losin). – Luke Woodward Sep 12 '20 at 13:09

0 Answers0