mysql - Generate numbers in range -- SQL -


I have to generate a random value in a range with a case statement. For example, we have the table of products as follows:

Products
TV
Fridge
Laptop

Now for testing me COSTPRICE, SALEPRICE requires the purpose of generating Since the price of the products is different from each other, so I need to generate values ​​in a category. For example, if the price is a TV, then generate value between 1000 to 1100 or if the price is a refrigerator, then generate value between 800-1000 and so on.

How can I view SQL Server using any idea / function? I know about the function RAND (), but I can not generate range values ​​with this

Please help at least push yourself to find a solution Thanks!

So you're basically looking for something like this:

  Product = 'TV' then (1000 + converter (INT, (101) * RAND ()) When the product = 'refrigerator' then select (800 + convert (INT, (201) * RAND ())) case From Manufacturer B> 0 and end  

When it comes to random number between @min The idea is very simple; @max See below:

  SELECT @min + CONVERT (INT, (max @ @ min + 1) * RAND ())  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -