I have a table which in which I would like to generate random numbers in a specific format (e.g. TEST-10256). For which I have been using the below: However I now want to update a table with these random numbers based on two columns, so the desired outcome would be this: I am not sure how to keep the same
Tag: random
Hide duplicate column cells in view
First of all, this here doesn’t solve my problem at all. I tried this too. I want generate random unique fake data (first name and address) I used the following SQL request: The result apparently looked like this (the addresses repeat themselves for the next name too): How do I make the first names AND addresses unique? Please note this
MySql query to return a random row returns unexpected number of rows
I am trying to get a random word from a long list of words in a MySql table: word_list [id*|wword]. My query looks at the moment like this: SELECT * FROM word_list w where id = (SELECT FLOOR(1 + RAND()*(10-1))) I thought the above query would return one and only one random row with Id between 1 and 9. To
Generating a list of random numbers, summing to a fixed amount using SQL
This question is about generating N random numbers whose sum is M(constant) using SQL. For example we have a number M=9.754. We need 10 random numbers whose sum is 9.754. It should be done in SQL Server environment. Can anybody help me? Answer While the @Squirrel answer is interesting but numbers here is more random here is the code:
SQL Select random rows partitioned by a column
I have a dataset looks like this and i need a query which returns 2 random values from where country in (‘a’, ‘c’): Answer This should work: Replace rand() with random() if you’re using Postgres or newid() in SQL Server.
T-SQL :: generate random Swiss National Identification Number (AHV/AVS)
I woul like to generate random Swiss National Identification Number (AHV/AVS). I found a website that can do that and if I look at the source code of the same page I can alos see the JavaScript code that can generate it. The numbers are generated following this pattern: 756: is the prefix number, it never changes 1234: is a
Want to run a query multiple times using a for loop and add each result into a dictionary. This code only execute once even as it loops through
I have a query that take a random sample of records. I want to do this multiple times and add each result into a dictionary, which I will concat into a pandas DataFrame later. This code only execute once even as it loops through. Answer cursor.fetchall() doesn’t execute the query, it just fetches the remaining results from the query that
Update columns based on calculation
My table looks like this: I have a list of id’s connected to datestamps. I can manage to calculate the difference between their latest and first entry as follows: However, I am unsure how I can update my table to reflect these calculations. What I want is the following: Answer In MySQL, you can self-join: I would not necessarily recommend
Generating never used before random number in SQL
I am using the function below to generate a random number between 0 and 99999999999. However, I need to make sure that the returned number has never been used before in the same app. In .net I would create a while loop and keep looping until the returned value is not found in a table that stores previously used values.
Hive: randomly select N values from distinct values of one column
Suppose I have a dataset like this I would like to randomly select, say, 3 values from the distinct ID values. One possibility is to get a table like this How shall I do that in Hive? Answer Here is one option using a join and rand(): The subquery randomly selects 3 ids, then the outer query brings all related