Skip to content

Tag: sql

DB2 SQLPL – Unable to exit Infinite loop

I have a stored procedure created to calculate the standard deviation by hand by going through each row in Employees Table in DB2 Sample Database – However, the procedure is stuck in an infinite loop. I am not sure as to why it is stuck as i expected the SQLSTATE to not be ‘00000’ after read…

Python Pandas non equal join

Have table OUT Need: so i need make non equal join equivalent SQL query : or as SQL query: The problem in PANDAS is that NON EQUAL SELF JOIN cannot be done with MERGE. And I can’t find another way….. Answer We can solve this in pandas in a smarter way by using groupby with agg and joining the stri…

Upsert on an array column

I am trying to do an upsert on the array column but I am not able to achieve the following result. Table name settings id primary key unique user_id foreign_key integer unique friends array tags …

How to rank players highest score

I have two tables I would like the output to look like Currently my code looks like but my output is I’m not sure how to get distinct player names, my attempts at using DISTINCT have not been working out. I’m just learning so apologies if this is something really obvious, i’ve tried to look …

Performance improvement Outer Apply

I have a query which runs slower. Order By inside the Outer Apply is very costly, is there any better way to write this query ? Answer From what I can tell in the code, you seem to be implementing a variation of lag(ignore nulls). Here is a better way: Also note that in many databases the “v” in v…

ORDER BY Has Error on Run Query With Case When

I have this query: And my tables are like this: table1 table2 When I run this query, I get this error: ORDER BY items must appear in the select list if SELECT DISTINCT is specified. What’s wrong whit this code? If I remove Else it works fine Answer A case expression returns a single value, with a single…

Mysql Left join index

I used the following query To display items from two tables, where the id of the first table is the item_id of the second. My question is , when I try to display this in php , if I want to display a.id i can try with: or since both tables have id,on the first example displays only if there