I have this table and an insert command is the following: The table contains random codes for each product_id. I want to get one unused code randomly (LIMIT 1 is ok for the job), mark the code as used and return it to the next layer. So far I did this: but this does not work well when multiple threads
Tag: mysql
Convert Postgre query to Hive/ Mysql
I have this table: I want to a situation where each footballer appears only once in a new table. For instance, Messi appears twice, but I want to take any occurrence of Messi in the new table. I am not sure how to convert it to either Hive or mysql. This is what I want the desired results to look
Calculating a 7 day average
I have this query. I want to generate the 7 day average of the mappings column. For example, I want to calculate the average mappings for each day (from 2020-01-03 – 2020-01-10). Results: Then return avg(avg_mapping) Answer I don’t see how your question relates to a rolling average. From your data…
mysql – fetch related rows from multiple tables without all combinations
Let’s say I have a primary table record, and it has 2 related tables fields and comments. I would like to run one query that fetches a set of records AND fetches all the related fields for that record, AND fetches all the comments related to that record. If I do left joins to ensure I get the records, I
Count how many times a rows enter time is within the enter and exit times of all other rows
I am looking to estimate a queue length for historical data at the time a record enters the queue. I would like to do this by counting how many of the rows in the data set have an enter time less than the enter time of the record, and an exit time greater than the enter time of the record.
MySQL select all column names where condition is met for specific row
I have a table which links users to groups which is set up as below: I would like to know if there is a method to select all groupIDs (column names) where a certain condition is met. E.g. if I want to find all groups where user 2 has a level greater than 0 it would return (1,2,4) It is
How can I use ORDER BY column_string like column_int when my column_string have letters?
I have a table like: —————— | ID | Animal | —————— | 1 | B1 | —————— | 2 | B2 | —————— | 3 | B3 | —————— | 4 | …
MYSQL no duplicate of 2 values
I couldn’t find an answer for this exact question although I am sure the information is on here somewhere. I have a python script that is adding stock data into a database. For each stock database has ~1000 lines where ‘ticker’ is the stock name and ‘time’ is the date(1 for each …
Return multiple records, but it should limit 1 record per each similar condition
Expected results: Explanation: In the results, James is representing all people aged 20. And Blue is representing all people aged 15. And so on.. Question: How can this query type of query be achieved? Thank you. Answer If you want one name per age, you can use: If you want the first row, then:
Finding the person with highest salary on mysql sample database
I have this mysql sample database (https://dev.mysql.com/doc/employee/en/sakila-structure.html). The question is i need to find top10 persons with highest salaries on the database. So far ive tried …