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
Efficient way to handle below query? in SQLServer or PostgreSql (Self join)
I have an employee table as below I need to select employee_id, manager_id, result. result should have true or false depends on below conditions. If the employee is manager for someone then true If the employee has a manager then true I came up with a query, but I need to know if there are any other better wa…
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
PostgreSQL. constraint allowing only one of many possible values
I have statuses like this: started,calculated,finished I need a constraint allowing only one NOT finished status in a table. This is allowed: this is forbidden due to two not finished statuses: Answer You can use a filtering unique index: The trick is to pass a fixed value instead of a column name to the on c…
Calling stored function in postgres 12 with json type argument by SQL query from pgAdmin results in error
I’m trying to call a stored function in postgres 12 DB which takes 1 parameter of json type and returns result of json type. The function is like this: The function must take a json with keys: “id” – for id of request sender, “token” – for it’s secret and “…
Get the immediate parent child relation in a table
I have a table with following value I need the output data from the above in the following format : Thanks in advance for any guidance on this. EDIT : I used the while loop approach to achieve this but trying to avoid the while loop. The while loop logic worked if proper sequence of ranklvl is there for a
JOINING the Same Tables in SQL
I have a table with 4 columns such as Customer ID, Person ID, Year, Unit Cost. I want to join the same table with all the years from table and keep the all years for all customer ID and PErson ID’s. IF there is no data in the table for respective customer ID and PErson ID then I want the
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
How to list all schemas and tablespaces in Oracle from .dmp file without importing?
So, the problem is that I have the .DMP file that was exported by a customer using exp or expdp. I want to get some of the .dmp properties, as I do in SQLServer using the following command: RESTORE HEADERONLY FROM DISK = N”C:tempmyfile.bak”; The original tablespace and schema are the infos I need …