Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

I would like to know is there a way to select randomly generated numbers between 100 and 500 along with a select query.

Eg: SELECT name, address, random_number FROM users

I don't have to store this number in DB and only to use it to display purpose.

I tried it something like this, but it can't get to work...

SELECT name, address, FLOOR(RAND() * 500) AS random_number FROM users

I hope someone helps me out.Thank you

1 Answer

0 votes
by (40.4k points)

Try this code::

FLOOR(RAND() * 401) + 100

Usually, FLOOR(RAND() * (<max> - <min> + 1)) + <min> generates a number between <min> and <max> inclusive.

You can also try this:

SELECT name, address, FLOOR(RAND() * 401) + 100 AS `random_number` 

Related questions

0 votes
1 answer
asked Jul 9, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Dec 31, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 20, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 12, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Dec 22, 2020 in SQL by Appu (6.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...